w3c / json-ld-syntax

JSON-LD 1.1 Specification
https://w3c.github.io/json-ld-syntax/
Other
111 stars 22 forks source link

Question: What is the difference between @context and @type #381

Closed lambdakris closed 2 years ago

lambdakris commented 2 years ago

Hi, I have a question about the difference between context and type. Now, I obviously see the numerous structural differences, but what I'm wondering is, what does a context mean that a type doesn't mean, and when would you use a type instead of a context (and sub-contexts)? Or asked a different way, what does using a context get you that using a type doesn't and vice versa?

pchampin commented 2 years ago

@context is the cornerstone of JSON-LD: it dictates how all other attributes in the JSON document must be interpreted (and ultimately converted into RDF triples). Its role is prescriptive. @type is just one special attribute, which translates to rdf:type. Its role is purely descriptive in that respect.

Now, things actually get a little more complicated in JSON-LD 1.1 with type-scoped contexts [1]: the top-level context can contain a directive saying "if @type has this value, then apply locally these additional context rules". It may look like @type is acting like a context in this situation, but this is actually driven by the top-level context, not by @type itself. I hope this helps.

[1] https://www.w3.org/TR/json-ld11/#example-46-defining-an-context-within-a-term-definition-used-on-type

lambdakris commented 2 years ago

@pchampin thank you so much for this explanation! The part about type scoped contexts is exactly what had thrown me off initially and your explanation addresses it precisely.

VladimirAlexiev commented 4 months ago

@lambdakris One more clarification:

translates to rdf:type

That pertains to nodes (subjects). But @type when applied to values (objects) means a datatype (eg xsd:integer).