In JSON-LD, can you expand the context?
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 created at runtime (object Marty P
), but the prefix definition is foaf
static and repeated for each document.
If I have 10 prefix definitions, it seems wasteful to me to put them in 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 it possible?
source to share
Each @context
can actually be multiple objects (or URLs), which are then concatenated in the order they appear (so that the meaning of the terms can be changed - a caveat there ).
For this you use an array where you can mix local and external contexts. Here is your example
{
"@context":
[
"http://example.com/base_context.jsonld",
{
"@vocab": "http://example.com/"
}
]
}
Under Section 6.7 describes the JSON-LD specification.
source to share