3

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"
 }
}

1 Answers1

5

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.

BigBlueHat
  • 2,355
  • 25
  • 30
unor
  • 92,415
  • 26
  • 211
  • 360
  • @BigBlueHat: Thanks for your edit :) Did you remove `@vocab` because it’s shorter, or is there something else to it? – unor Jun 04 '18 at 15:32
  • 1
    happy to help. :) Using `@vocab` states a simple prefix for all related identifiers whereas using an IRI as a direct value of `@context` states the use of a context file--which can define thing well beyond simple prefixing. Hope that helps! – BigBlueHat Jun 04 '18 at 20:16
  • Can you use compact IRIs in context?`"@context": { "schema": "http://schema.org/", "note": "schema:description" },` – Mzq Jul 06 '18 at 04:21
  • @Miranda: Yes, should be fine. – unor Jul 06 '18 at 10:25