What is the use of @vocab in JSON-LD and what is the difference with @context?

What is an attribute @vocab

in JSON-LD? As I see it, you can "import" the remote dictionary, but isn't that the same as what you can do with @context

? If I am not mistaken, you can "import" the remote source for @context

. So where is the difference between @vocab

and @context

?

Additional question: can I have more than one @vocab

? For example, the first links to schema.org and others to rdfs?

+3


source to share


1 answer


@vocab

is used specifically to declare a default dictionary from which all terms are derived, without having to declare specific collations for each term (as you usually do in @context

).

For example, see this snippet (taken from the JSON-LD 1.0 spec ):

{
  "@context": {
    "@vocab": "http://schema.org/"
  }
  "@id": "http://example.org/places#BrewEats",
  "@type": "Restaurant",
  "name": "Brew Eats"
  ...
}

      

This snippet is @vocab

used to specify that in this context all terms are derived from the schema.org dictionary. So, in the following snippets, it is Restaurant

mapped to http://schema.org/Restaurant

, and name

mapped to http://schema.org/name

. You could of course do it with explicit mappings in @context

:



{
  "@context": {
    "Restaurant": "http://schema.org/Restaurant",
    "name" : "http://schema.org/name" 
  }
  "@id": "http://example.org/places#BrewEats",
  "@type": "Restaurant",
  "name": "Brew Eats"
  ...
}

      

but it quickly gets tedious as you start using more and more terms from the same vocabulary. @vocab

is just a useful shorthand way of saying "if I don't have an explicit mapping for a term, that's what it matches."

As for whether more than one can be used @vocab

: you can have more than one @vocab

in a JSON-LD document (just like you can have more than one @context

), but you cannot have more than one in the same @context

. I believe the explanation that it defines the default also makes it clear why you can't have two in the same context.

+6


source







All Articles