papa zulu
papa zulu

Reputation: 317

JSON-LD can't define multiple node types in @context

The documentation of JSON-LD types clearly states that you can define multiple types to a node. https://www.w3.org/TR/json-ld11/#specifying-the-type If you open the example #14 from the above url in the JSON-LD playground, you will see that it is a valid syntax.

{
    "@id": "http://me.markus-lanthaler.com/",
    "@type": [
      "http://schema.org/Person",
      "http://xmlns.com/foaf/0.1/Person"
    ]
}

However, if you try to move this definition into @context, and apply it to a specific property, you will get an error from the parser. Check it here.

{
  "@context": {
    "some_property": {
      "@id": "http://me.markus-lanthaler.com/",
      "@type": [
        "http://schema.org/Person",
        "http://xmlns.com/foaf/0.1/Person"
      ]
    }
  },
  "some_property": "value"
}

The error displayed is: jsonld.SyntaxError: Invalid JSON-LD syntax; an @context @type value must be a string.

I read the documentation carefully and it says that you can define multiple types for node types, but not for value objects. The documentation clearly says that when @value and @type are used in the same dictionary, the @type keyword is expressing a value type. Otherwise, the @type keyword is expressing a node type. But here is another example showing that this might not be true.

Does anybody have an idea how to define multiple node types in @context?

Upvotes: 2

Views: 1673

Answers (1)

Michał Politowski
Michał Politowski

Reputation: 4385

You cannot, because you cannot define node types in a context at all.

Starting normatively. In https://www.w3.org/TR/json-ld11/#context-definitions we read:

If the expanded term definition contains the @type keyword, its value MUST be an absolute IRI, a compact IRI, a term, null, or one of the keywords @id, @json, @none, or @vocab.

No arrays allowed here. Because @type in an expanded term definition in a context is used to specify the type of values of the defined property. As mentioned eg. in https://www.w3.org/TR/json-ld11/#typed-values:

Typed values may be expressed in JSON-LD in three ways:

  1. By utilizing the @type keyword when defining a term within an @context section.

Finally let's see what your example expands to if we correct it to have a string value for @type.

{
  "@context": {
    "some_property": {
      "@id": "http://me.markus-lanthaler.com/",
      "@type": "http://schema.org/Person"
    }
  },
  "some_property": "value"
}

expands to

[
  {
    "http://me.markus-lanthaler.com/": [
      {
        "@type": "http://schema.org/Person",
        "@value": "value"
      }
    ]
  }
]

As you can see there you indeed have @value and @type together.

Upvotes: 2

Related Questions