Skip to content

JSON-LD context

Generate a JSON-LD 1.1 context or frame for the JSON data of the schema.

Terminal window
ohi get w3c/prov-o
ohi linkml to jsonld-context --full-uris \
--to prov-o.context.jsonld prov-o.linkml.yaml
Try it in the playground, with PROV-O

The context is for documents whose top object is the tree root class, or a list of such objects.

context_urlstring
CLI --context-urlScala contextUrl

With frame, the URL of the context, to put in the frame instead of the context.

framebooleandefault false
CLI --frame

Whether to write a JSON-LD frame instead of the context. The frame turns RDF of the schema's data back into JSON of the same shape.

full_urisbooleandefault false
CLI --full-urisScala fullUris

Whether to write URIs in full, instead of compacting them to CURIEs with the schema's prefixes.

indentation_stepintegerdefault 2
CLI --indentation-stepScala indentationStep

The number of spaces for each level of indentation in the output.

tree_rootstring
CLI --tree-rootScala treeRoot

The class at the top of the JSON documents, instead of the class with tree_root: true.

LinkML JSON-LD
Slot Term for its alias or name, with the slot URI as @id
Identifier Alias of @id
Type designator Alias of @type, plus a term for each class
Reference, uri, curie, uriorcurie "@type": "@id"
Other types, except integer and boolean "@type" with the type’s URI
Enum "@type": "@vocab", with a term for each value
implicit_prefix "@type": "@vocab", with the prefix as @vocab
langstring "@container": "@language"
Dict keyed by the identifier "@container": "@id"
Dict keyed by a key slot "@container": "@index"
Other multivalued slots "@container": "@set"

A key with different meanings in different classes gets a scoped context.

The RDF made with the context won’t have rdf:type for an object, unless the JSON has a type designator. The generator lists everything else a context could not express:

  • An identifier of a string range doesn’t also become a literal.
  • An identifier or reference that is a number or boolean isn’t an IRI.
  • An identifier with an implicit_prefix is resolved against the base IRI.
  • A SimpleDict with plain values, and a tree root that is a dict.
  • A value of range Any.
  • A list that mixes plain texts and texts in several languages.
  • A decimal with a fraction, written as "1.5E0"^^xsd:decimal.
  • Ranges that need different terms, such as string and uri.
  • A key or enum value with : or / that isn’t its own IRI.
  • A prefix with the same name as a key.
  • A key with different meanings in different classes, without a tree root, or in objects nested in each other.
  • Too many such keys: scoped contexts stop at 10,000 terms.

When the frame option is enabled, the generator writes a JSON-LD frame with the context in it. Alternatively, you can reference an external context by setting the context_url option. Framing RDF of the schema’s data gives JSON of the same shape as the schema’s JSON, with @type on each object. Frame with native types, such as useNativeTypes in JSON-LD processors.

The frame matches objects of the tree root class, embeds inlined objects, and leaves references as IRIs. Besides the limits above, these don’t come back as they were:

  • float, double and decimal values. Their key is the slot’s full IRI instead of its name.
  • A number or boolean in a slot whose other ranges are enums or references.
  • Text without a language, which ends up under @none.
  • uri values, which can become CURIEs.
  • String identifiers, and references to them, which become full IRIs.
  • Objects of the tree root class inside other objects, which also show up at the top.

The generator emits a warning every time it encounters one of these limitations.

The CLI prints the warnings to stderr. In the bindings, jsonld_context_with_warnings (jsonldContextWithWarnings in JavaScript) returns the document with its warnings.