Cnoor0171
Cnoor0171

Reputation: 374

Are keys with ":" (colon) allowed in the "@context" of a json-ld graph?

Are json-ld contexts allowed to have ":" in their keys? For example, is the following a valid json-ld document?

{
  "@context": {
    "abc:def": "http://abc-def.com/"
  },
  "@graph": [
    {
      "abc:def": "something"
    }
  ]
}

I couldn't find any specific information on the spec. I tried to parse the above document using two of the most popular python libraries pyld and rfdlib-jsonld and one of them considers it an error, while the other parses fine. I also tried some online json-ld playgrounds and they also disagree on whether the above document is well formed.

pyld gives an error saying Invalid JSON-LD syntax; term in form of IRI must expand to definition., while rdflib-jsonld expands it to

[
  {
    "http://abc-def.com/": [
      {
        "@value": "something"
      }
    ]
  }
]

which one is correct?

Upvotes: 0

Views: 334

Answers (1)

kidney
kidney

Reputation: 3083

According to the JSON-LD 1.1 spec [1], it should be possible to use compact IRIs in @context. However, the IRI prefix should exist in the context:

The compact IRI is expanded by concatenating the IRI mapped to the prefix to the (possibly empty) suffix. If the prefix is not defined in the active context, or the suffix begins with two slashes (such as in http://example.com), the value is interpreted as IRI instead.

So, your example should probably be transformed to something like:

{
  "@context": {
    "abc": "http://example.org/",
    "abc:def": {
      "@type": "@id"
    }
  },
      "abc:def": "something"
}

Checked at JSON-LD playground [2] which should conform to the specification.

So the answer would be Yes, it is possible to use a 'colon' in JSON-LD @context. And I'd say pyld behaves according to the specification.

Upvotes: 3

Related Questions