Late Developer
Late Developer

Reputation: 29

Multiple contexts in JSON-LD

How can I access two seperate vocabs in JSON-LD, can I use 2 @contexts? e.g.

{
"@context": {
  "@vocab": "http://schema.org/",
  "first_name": "givenName",
  "last_name": "familyName
  }
"@context": {
  "@vocab": "http://our_own_schema.org/",
  "Time": "inputTime"
 }
}

Upvotes: 3

Views: 3981

Answers (1)

unor
unor

Reputation: 96607

You can provide multiple @context. If they contain duplicated terms, the most recently defined term gets used. See examples 27 and 28. But if you want to mix vocabularies within the same object, this doesn’t work.

To allow mixing vocabularies within the same object, you could define all vocabularies in the @context at the top of the document. Each vocabulary can have a prefix, which allows you to use compact IRIs. One vocabulary can be the default one (without prefix).

  • With default vocabulary:

    "@context": 
    [
      "http://schema.org/",
      {"oos": "http://our_own_schema.org/"}
    ],
    

    The key name expands to http://schema.org/name,
    the key oos:name expands to http://our_own_schema.org/name.

  • Without default vocabulary:

    "@context": 
    {
      "schema": "http://schema.org/",
      "oos": "http://our_own_schema.org/"
    },
    

    The key name would be ignored,
    the key schema:name expands to http://schema.org/name,
    the key oos:name expands to http://our_own_schema.org/name.

Note: It’s always possible to use absolute IRIs as keys. You don’t have to define these in a context.

Upvotes: 5

Related Questions