JSON-LD | JavaScript: Behavioral Layer

Standards Based Development

json-ld is a json-based Serialization for Linked Data

json is a useful data serialization and messaging format. This specification defines json-ld, 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. It is primarily intended to be a way to use Linked Data in Web-based programming environments, to build interoperable Web services, and to store Linked Data in json-based storage engines.

Linked Data [LINKED-DATA] is a way to create a network of standards-based machine interpretable data across different documents and Web sites. It allows an application to start at one piece of Linked Data, and follow embedded links to other pieces of Linked Data that are hosted on different sites across the Web.

json-ld is a lightweight syntax to serialize Linked Data in json [RFC4627]. Its design allows existing JSON to be interpreted as Linked Data with minimal changes. json-ld is primarily intended to be a way to use Linked Data in Web-based programming environments, to build interoperable Web services, and to store Linked Data in json-based storage engines. Since json-ld is 100% compatible with JSON, the large number of json parsers and libraries available today can be reused. In addition to all the features json provides, json-ld introduces:

  • a universal identifier mechanism for JSON objects via the use of iris,
  • a way to disambiguate keys shared among different JSON documents by mapping them to iris via a context,
  • a mechanism in which a value in a JSON object may refer to a JSON object on a different site on the Web,
  • the ability to annotate strings with their language,
  • a way to associate datatypes with values such as dates and times,
  • and a facility to express one or more directed graphs, such as a social network, in a single document.

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, if desired, for use with other Linked Data technologies like SPARQL. Developers who require any of the facilities listed above or need to serialize an RDF Graph or RDF Dataset in a JSON-based syntax will find json-ld of interest. People intending to use json-ld with RDF tools will find it can be used as another RDF syntax, like Turtle [TURTLE]. Complete details of how json-ld relates to RDF are in section 9. Relationship to RDF.

The syntax is designed to not disturb already deployed systems running on JSON, but provide a smooth upgrade path from JSON to json-ld. Since the shape of such data varies wildly, json-ld features mechanisms to reshape documents into a deterministic structure which simplifies their processing.

json for Linking Data

Data is messy and disconnected. json-ld organizes and connects it, creating a better Web.

Embedding json-ld in html Documents

script elements can be used to embed blocks of data in documents. This way, json-ld content can be easily embedded in html by placing it in a script element with the type attribute set to type="application/ld+json".

Example 62: Embedding json-ld in html:

Script


<script type="application/ld+json">
{
  "@context": "http://json-ld.org/contexts/person.jsonld",
  "@id": "http://dbpedia.org/resource/John_Lennon",
  "name": "John Lennon",
  "born": "1940-10-09",
  "spouse": "http://dbpedia.org/resource/Cynthia_Lennon"
}
</script>      

Depending on how the html document is served, certain strings may need to be escaped.

Defining how such data may be used is beyond the scope of this specification. The embedded json-ld document might be extracted as is or, e.g., be interpreted as RDF.

If json-ld content is extracted as RDF [RDF11-CONCEPTS], it should be expanded into an RDF Dataset using the Deserialize json-ld to RDF Algorithm [json-ld-api].Embedding json-ld in html Documents

json-ld, or JavaScript Object Notation for Linked Data, is a method of transporting Linked Data using JSON. It was a goal to require as little effort as possible from developers to transform their existing JSON to json-ld. This allows data to be serialized in a way that is similar to traditional json. It is being standardised inside of the World Wide Web Consortium rdf Working Group (currently a "w3c Candidate Recommendation").

json-ld is designed around the concept of a "context" to provide additional mappings from JSON to an RDF-like model. The context links object properties in a JSON document to concepts in an ontology. In order to provide some basic interoperability with RDF, json-ld allows values to be coerced to a specified type or to be tagged with a language. A context can be embedded directly in a json-ld document or put into a separate file and referenced from different documents (from traditional json documents via an http Link header).

The following example describes a person, based on the foaf vocabulary:


{
  "@context": {
    "name": "http://xmlns.com/foaf/0.1/name",
    "homepage": {
      "@id": "http://xmlns.com/foaf/0.1/workplaceHomepage",
      "@type": "@id"
    },
    "Person": "http://xmlns.com/foaf/0.1/Person"
  },
  "@id": "http://me.markus-lanthaler.com",
  "@type": "Person",
  "name": "Markus Lanthaler",
  "homepage": "http://www.tugraz.at/"
}

In order for the above example to correctly describe a person, based on foaf, first, the two json properties name and homepage and the type person are mapped to concepts in the FOAF vocabulary and the value of the homepage property is specified to be of the type @id, i.e., it is specified to be an iri in the context definition. Based on the rdf model, this allows the person described in the document to be unambiguously identified by an iri. The use of resolvable iris allows RDF documents containing more information to be transcluded which enables clients to discover new data by simply following those links; this principle is known as Follow Your Nose.

By having all data semantically annotated as in the example, a RDF processor can identify that the document contains information about a person (@type) and if the processor understands the FOAF vocabulary it can determine which properties specify the person’s name and the homepage of the person.

json-ld

json-ld Examples

Illustration of JSON-LD Document Data Model

Figure 1: An illustration of the data model.

json-ld Documents

References and Resources