JSON-LD

Bringing Linked Data and JSON together for a lightweight, structured, semantic data serialization format.

The JSON-LD set of standards standards are maintained by the Resource Description Framework (RDF) Working Group.

No extra processors or software libraries are necessary to use JSON-LD in its most basic form. The language provides developers with a very easy learning curve. Developers only need to know JSON and two keywords (@context and @id) to use the basic functionality in JSON-LD.

Generally speaking, the data model described by a JSON-LD document is a labeled, directed graph. The graph contains nodes, which are connected by edges. A node is typically data such as a string, number, typed values (like dates and times) or an IRI. There is also a special class of node called a blank node, which is typically used to express data that does not have a global identifier like an IRI. Blank nodes are identified using a blank node identifier. This simple data model is incredibly flexible and powerful, capable of modeling almost any kind of data. For a deeper explanation of the data model, see section § 5. Data Model.

From https://json-ld.org/spec/latest/json-ld/

JSON-LD was created for Web Developers who are working with data that is important to other people and must interoperate across the Web. As per one of lead editor of the draft The desire for better Web APIs is what motivated the creation of JSON-LD, not the Semantic Web.

From https://www.w3.org/2013/dwbp/wiki/RDF_AND_JSON-LD_UseCases

See formats, IRI (Internationalized Resource Identifiers)

Implementations

In Javacript https://github.com/digitalbazaar/jsonld.js

In Rust https://github.com/timothee-haudebourg/json-ld

Examples

The following example from json-ld.org is overly verbose and difficult for humans to parse.

{
  "http://schema.org/name": "Manu Sporny",
  "http://schema.org/url": { "@id": "http://manu.sporny.org/" },  ← The '@id' keyword means 'This value is an identifier that is an IRI'
  "http://schema.org/image": { "@id": "http://manu.sporny.org/images/manu.png" }
}

But JSON-LD has a special context object where you can map terms to certain keywords.[1]

{
  "@context": {
    "name": "http://schema.org/name",  ← This means that 'name' is shorthand for 'http://schema.org/name' 
    "image": {
      "@id": "http://schema.org/image",  ← This means that 'image' is shorthand for 'http://schema.org/image' 
      "@type": "@id"  ← This means that a string value associated with 'image' should be interpreted as an identifier that is an IRI 
    },
    "homepage": {
      "@id": "http://schema.org/url",  ← This means that 'homepage' is shorthand for 'http://schema.org/url' 
      "@type": "@id"  ← This means that a string value associated with 'homepage' should be interpreted as an identifier that is an IRI 
    }
  },
  "name": "Sebastian Gorton Kalvik",
  "homepage": "https://aaa.pm"
}

We could then add the keys "homepage" and "name" to the root of our object and it would be implicit that homepage refers to http://schema.org/url and http://schema.org/name. Both computer and human readable.

If a simple JSON object is available at a IRI as https://example.org/my-context.jsonld we can reference it directly from another document:

{
  "@context": "https://example.org/my-context.jsonld",
  "name": "Sebastian Gorton Kalvik",
  "homepage": "https://aaa.pm"
}

The referenced context not only specifies how the terms map to IRIs in the Schema.org vocabulary but also specifies that string values associated with the homepage and image property can be interpreted as an IRI ("@type": "@id").[2]