Skip to content
AnswerWell geo Documentation

Research · 9 min read · Answerwell

JSON-LD Context, IRIs and Graph Serialization

How W3C JSON-LD 1.1 maps JSON to Linked Data with @context, identifiers, lists, named graphs, and HTML or HTTP delivery.

This page summarizes the W3C JSON-LD 1.1 recommendation and related processing documents. JSON-LD lets you keep ordinary JSON payloads while adding vocabulary-backed meaning for machines that expand graphs, and it is widely used inside HTML pages and HTTP APIs.

JSON is a useful data serialization and messaging format. This specification defines JSON-LD 1.1, a JSON-based format to serialize Linked Data. The syntax is designed to easily integrate into deployed systems that already use JSON, and provides a smooth upgrade path from JSON to JSON-LD.

— W3C, JSON-LD 1.1

JSON-LD vs plain JSON: when you need @context

Section titled “JSON-LD vs plain JSON: when you need @context”

JSON-LD is valid JSON: every JSON-LD document is a valid JSON document per JSON-LD 1.1. The difference is interpretation. Plain JSON keys are opaque strings; JSON-LD uses a context to map those keys to IRIs so data can link across sites.

Linked Data [LINKED-DATA] is a way to create a network of standards-based machine interpretable data across different documents and Web sites.

— W3C, JSON-LD 1.1

JSON-LD is designed to be usable directly as JSON, with no knowledge of RDF [RDF11-CONCEPTS]. It is also designed to be usable as RDF in conjunction with other Linked Data technologies like SPARQL [SPARQL11-OVERVIEW].

— W3C, JSON-LD 1.1

Use JSON-LD when consumers need stable identifiers, vocabulary terms (for example schema.org or FOAF), or RDF pipelines. Teams that only pass JSON through application code can include @context and treat it as ignorable metadata—the spec’s Zero Edits, most of the time design goal—while Linked Data tools use the same file. Algorithms such as expand, compact, flatten, and frame are defined in JSON-LD 1.1 Processing Algorithms and API; framing shapes are in JSON-LD 1.1 Framing.

A context maps terms (short JSON keys) to IRIs and can set defaults such as @vocab and @base.

Simply speaking, a context is used to map terms to IRIs.

— W3C, JSON-LD 1.1

  • Inline @context keeps everything in one file and works offline.
  • Remote contexts are IRIs; only the remote document’s @context key is used—extra keys are ignored. Example pattern: person.jsonld.
  • Arrays of contexts apply in order; when the same term is defined twice, the most recent definition wins.

JSON-LD 1.1 adds scoped contexts (nested @context inside a term definition), @import (merge a remote context, with the wrapping context winning—see remote-context.jsonld), @protected (block silent term overrides), and @propagate (control whether scoped context flows to child nodes).

Documents that use 1.1 features should declare mode explicitly:

Setting the processing mode explicitly to json-ld-1.1 is RECOMMENDED to prevent a JSON-LD 1.0 processor from incorrectly processing a JSON-LD 1.1 document and producing different results.

— W3C, JSON-LD 1.1

In the context, @version takes the numeric value 1.1, not the string json-ld-1.1. JSON-LD 1.1 is a superset of 1.0; older documents usually remain compatible except where the spec notes exceptions.

IRIs, @id, and properties that processors ignore

Section titled “IRIs, @id, and properties that processors ignore”

A string is an IRI when it is the value of @id (or when type coercion maps a property to IRIs). Relative references resolve against @base; vocabulary-relative properties use @vocab, not base.

JSON keys that do not expand to an IRI, such as status in the example above, are not Linked Data and thus ignored when processed.

— W3C, JSON-LD 1.1

Any key that does not expand to an IRI, a blank node, or a keyword drops out of the Linked Data view— a common surprise when mixing app fields with vocabulary properties.

On a node object, @type names the resource (often one or more vocabulary types). On a value object that includes @value, @type gives the datatype of the literal (for example xsd:dateTime), not the type of a nested resource. The same keyword plays two roles; the presence of @value tells you which.

Value objects MUST have @value. They MUST NOT combine @type with @language or @direction at the same time. Language tags follow BCP47; base direction uses @direction (ltr, rtl, or null) as described with Strings on the Web: Language and Direction Metadata.

In ordinary JSON, array order matters to many apps. In JSON-LD, unless you opt in, arrays are unordered multisets in the data model:

Unless the processing mode is set to json-ld-1.0, arrays in JSON-LD do not convey any ordering of the contained elements by default.

— W3C, JSON-LD 1.1

Goal Mechanism
Preserve order (RDF list) @list on a value, or @container: @list in the context
Force unordered array shape after compact @container: @set in the context (body @set is syntactic sugar and is optimized away on expand)
Multiple values, order not significant Default array behavior

Use @list for sequences where order is semantic (coordinates, ranked items). Do not assume JSON array order survives expansion without @list.

Term definitions can require specific JSON shapes:

@container Keys represent Typical use
@language BCP47 tags Translations keyed by locale
@index App-defined indexes Side tables; index keys may not round-trip to RDF
@id Node identifiers Object stores keyed by IRI
@type Type IRIs Polymorphic bundles
@graph Named graph slots Datasets in one document

As data indexes are not preserved when round-tripping to RDF; this feature should be used judiciously.

— W3C, JSON-LD 1.1

Property-based index maps (1.1) tie index keys to a semantic property via @index in the term definition so values survive expansion more meaningfully than plain index maps.

  • @nest groups properties in nested objects for readability; expansion flattens them onto the parent node.
  • @included lists extra node objects for flattening workflows (similar intent to compound documents in some API styles).
  • @graph holds one or more node objects in a named or default graph; a graph object may carry @id as the graph name.

A JSON-LD document serializes an RDF dataset: one default graph plus zero or more named graphs. Consumers that only understand a single graph must use the default graph and ignore named graphs when interpreting as classic RDF.

a consumer MUST only use the default graph and ignore all named graphs

— W3C, JSON-LD 1.1

Embedded node objects create structure; @id references link without duplication. Blank node identifiers (_:…) are document-scoped—prefer dereferenceable IRIs when other documents must point at the same resource.

Document forms: expand, compact, flatten, frame

Section titled “Document forms: expand, compact, flatten, frame”

Processors normalize documents through defined profiles (IRIs under http://www.w3.org/ns/json-ld#):

Form Purpose
Expanded All IRIs explicit; context not required for processing
Compacted Human-friendly terms via a context
Flattened Top-level @graph; stable blank-node labels
Framed Shape enforced by a frame document (framing spec)

The profile parameter on media type application/ld+json can request these forms over HTTP (RFC 6906); servers SHOULD honor recognized profiles and MUST ignore unknown ones. A profile does not change semantics for clients that ignore it.

Section titled “HTTP Link header and HTML application/ld+json”

Upgrading application/json without editing the body

Section titled “Upgrading application/json without editing the body”

For JSON served as application/json, a single Link header can attach a context:

processors MUST attempt to retrieve any JSON-LD document referenced by a Link Header with: rel=“http://www.w3.org/ns/json-ld#context”, and type=“application/ld+json”.

— W3C, JSON-LD 1.1

That supports the “zero edits” path: one HTTP header plus existing JSON.

When the body is already application/ld+json, all context must live in the document—Link-header contexts are ignored:

Please note that JSON-LD documents served with the application/ld+json media type MUST have all context information, including references to external contexts, within the body of the document. Contexts linked via a http://www.w3.org/ns/json-ld#context HTTP Link Header MUST be ignored for such documents.

— W3C, JSON-LD 1.1

In HTML, embed JSON-LD in <script type="application/ld+json">. Multiple such scripts in one page form a single dataset with shared blank-node scope unless fragment targeting applies. Set @base or use absolute IRIs when the document URL can change; escape &, <, >, ", and ' in script bodies per HTML rules.

JSON-LD is a concrete RDF syntax as described in [RDF11-CONCEPTS]. Hence, a JSON-LD document is both an RDF document and a JSON document

— W3C, JSON-LD 1.1

Deserialize paths run expand → flatten → triples (API spec). Compared to Turtle, JSON numbers map to XSD types via JSON’s own number rules (fractions become xsd:double, not necessarily xsd:decimal). @json literals hold opaque JSON blobs; the spec treats them as rare:

JSON-LD is intended to allow native JSON to be interpreted through the use of a context. The use of JSON literals creates blobs of data which are not available for interpretation. It is for use only in the rare cases that JSON cannot be represented as JSON-LD.

— W3C, JSON-LD 1.1

Base direction may be lost in standard RDF round-trips unless you use API rdfDirection options (i18n-datatype or compound-literal). Language maps do not yet standardize per-locale direction in all cases—value objects with @direction are safer when direction matters.

  • Object keys in JSON-LD MUST be unique (unlike duplicate keys in permissive JSON parsers).
  • @context MUST NOT be aliased—unlike some legacy keyword aliases (url → @id, etc., which cannot appear inside context definitions).
  • Term definitions MUST NOT be circular.