5

I have a JSON-LD document.

{
  "@id": "VDWW1LL3MZ",
  "first_name": "Vincent",
  "last_name": "Willems",
  "knows":["MartyP"],
  "@context": {
    "foaf": "http://xmlns.com/foaf/0.1/",
    "first_name": "foaf:givenName",
    "last_name": "foaf:familyName",
    "knows": "foaf:knows",
    "MartyP": { 
      "@id": "http://example.com/martyp",
      "first_name": "Marty",
      "last_name": "P"
    }
  }
}

Now, part of the context of this document is generated in run-time (the Marty P object), but the foaf prefix definition is static, and repeated for each document.

If I have like 10 prefix definitions, it feel wasteful to put them in each and every document. So I would like to do something like

generated document:

{
  "@id": "VDWW1LL3MZ",
  "first_name": "Vincent",
  "last_name": "Willems",
  "knows":["MartyP"],
  "@context": {
    "@extends": "http://example.com/base_context.jsonld",
    "MartyP": { 
      "@id": "http://example.com/martyp",
      "first_name": "Marty",
      "last_name": "P"
    }
  }
}

base_context.jsonld:

  {
    "foaf": "http://xmlns.com/foaf/0.1/",
    "first_name": "foaf:givenName",
    "last_name": "foaf:familyName",
    "knows": "foaf:knows"
  }

Is this possible?

Maarten
  • 6,894
  • 7
  • 55
  • 90
  • 2
    By the way, the `MartyP` resource should not be inside the @context. The context serves only to translate JSON keys and values to URIs. Instead the `MartyP` object should be whole inside the `knows` array. Please do experiment with the [JSON-LD playgroud](http://json-ld.org/playground/) to get a hang of it. – Tomasz Pluskiewicz Oct 07 '14 at 12:53

1 Answers1

7

Each @context can actually be multiple objects (or URLs), which are then combined in the order that they appear (so that it is possible to change meaning of terms - caution there).

To do that you use an array, where you can mix local and external contexts. Here's your example

{
  "@context": 
  [
    "http://example.com/base_context.jsonld",
    {
      "@vocab": "http://example.com/"
    }
  ]
}

It's described in section 6.7 of JSON-LD specs.

Tomasz Pluskiewicz
  • 3,622
  • 1
  • 19
  • 42