digitalbazaar / jsonld.js

A JSON-LD Processor and API implementation in JavaScript
https://json-ld.org/
Other
1.66k stars 195 forks source link

URL could not be dereferenced; when compact jsonld #313

Closed linonetwo closed 5 years ago

linonetwo commented 5 years ago

I'm compact this document to remove the prefix fron keys:

// tiddlerJsonLd
{
  "@context": {
    "XML": "http://www.w3.org/2001/XMLSchema#",
    "dcterms": "http://purl.org/dc/terms/",
    "ldp": "http://www.w3.org/ns/ldp#",
    "m": "",
    "rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
    "rdfs": "http://www.w3.org/2000/01/rdf-schema#",
    "st": "http://www.w3.org/ns/posix/stat#",
    "terms": "http://purl.org/dc/terms/",
    "xsd": "http://www.w3.org/2001/XMLSchema#"
  },
  "@id": "m:",
  "@type": [
    "ldp:Container",
    "ldp:BasicContainer"
  ],
  "dcterms:modified": {
    "@type": "xsd:dateTime",
    "@value": "2019-05-11T04:14:28+00:00"
  },
  "st:mtime": {
    "@type": "xsd:decimal",
    "@value": "1557548068.527"
  },
  "st:size": 4096
}
// this.keyContext
{
  "created": "schema:dateCreated",
  "creator": "schema:creator",
  "text": "schema:text",
  "title": "dc:title",
  "tags": "schema:keywords",
  "type": "dc:type",
  "modified": "schema:dateModified",
  "modifier": "schema:contributor",
  "_canonical_uri": "schema:url"
}
jsonld.compact(tiddlerJsonLd, this.keyContext);

And it throws Error: URL could not be dereferenced; only "http" and "https" URLs are supported.

I just want to restore my prefix-less json.

aljones15 commented 5 years ago

you closed this so I'm assuming you solved the issue, but I believe the problem comes from this:

"m": "", "@id": "m:",

in your context m is declared as empty string then in the @id it thinks m must be an IRI. it doesn't have to be an IRI it could be a blank node or a keyword too, but the empty string is causing issues.