W3C

JSON-LD Algorithms 1.0 Algorithms for Processing JSON-LD Documents W3C Editor's Draft 25 December 2012 Algorithms and API

Final Community Group Specification 28 March 2013

This version: http://dvcs.w3.org/hg/json-ld/raw-file/default/spec/ED/json-ld-api/20121225/index.html Latest published version: editor's draft:
http://www.w3.org/TR/json-ld-api/ http://dvcs.w3.org/hg/json-ld/raw-file/spec/latest/json-ld-api/index.html
Latest editor's draft: Test suite:
http://dvcs.w3.org/hg/json-ld/raw-file/default/spec/latest/json-ld-api/index.html http://json-ld.org/test-suite/
Editors:
Manu Sporny Markus Lanthaler , Digital Bazaar Graz University of Technology
Gregg Kellogg , Kellogg Associates
Markus Lanthaler Manu Sporny , Graz University of Technology Digital Bazaar
Authors:
Dave Longley , Digital Bazaar
Manu Sporny , Digital Bazaar Gregg Kellogg , Kellogg Associates
Markus Lanthaler , Graz University of Technology
Manu Sporny , Digital Bazaar

This document is also available in this non-normative format: diff to previous version


Abstract

JSON [ RFC4627 ] has proven to be a highly useful object serialization and messaging format. JSON-LD [ JSON-LD ] harmonizes the representation of Linked Data in JSON by outlining a common JSON representation format for expressing directed graphs; mixing both Linked Data and non-Linked Data in a single document. This document outlines specification defines an Application Programming Interface (API) and a set of algorithms for programmatically transforming programmatic transformations of JSON-LD documents documents. By expressing the data in order to make them easier a way that is specifically tailored to work with in programming environments like JavaScript, Python, and Ruby. a particular use case, the processing typically becomes much simpler.

Status of This Document

This section describes the status of this document at specification was published by the time of its publication. Other documents may supersede this document. A list of current RDF Working Group . It is not a W3C publications and Standard nor is it on the latest revision of this technical report can be found in W3C Standards Track. Please note that under the W3C technical reports index Community Final Specification Agreement (FSA) at http://www.w3.org/TR/. other conditions apply. Learn more about W3C Community and Business Groups .

This document has been under development for over 18 25 months in the JSON for Linking Data Community Group. The document has recently been transferred to the RDF Working Group for review, improvement, and publication along the Recommendation track. The specification has undergone significant development, review, and changes during the course of the last 18 25 months.

There are several independent interoperable implementations of this specification. There is a fairly complete test suite and a live JSON-LD editor that is capable of demonstrating the features described in this document. While there will be continuous development on implementations, the test suite suite, and the live editor will continue, editor, they are believed to be mature enough to be integrated into a non-production system at this point in time with the time. There is an expectation that they could be used in a production system within the next year. six months.

Issue

It is important for readers to understand that the scope of this document is currently under debate and new features may be added to the specification. Existing features may be modified heavily or removed entirely from the specification upon further review and feedback from the broader community. This is a work in progress and publication as a Working Draft does not require that all Working Group members agree on the content of the document.

There are a number of ways that one may participate in the development of this specification:

This document was published by the RDF Working Group as an Editor's Draft. If you wish to make comments regarding this document, please send them to public-rdf-comments@w3.org ( subscribe , archives ). All feedback is welcome. Publication as an Editor's Draft does not imply endorsement by the W3C Membership. This is a draft document and may be updated, replaced or obsoleted by other documents at any time. It is inappropriate to cite this document as other than work in progress. This document was produced by a group operating under the 5 February 2004 W3C Patent Policy . W3C maintains a public list of any patent disclosures made in connection with the deliverables of the group; that page also includes instructions for disclosing a patent. An individual who has actual knowledge of a patent which the individual believes contains Essential Claim(s) must disclose the information in accordance with section 6 of the W3C Patent Policy .

Table of Contents

1. Introduction

This section is non-normative.

This document is a detailed specification for an Application Programming Interface for the JSON-LD Syntax. syntax. The document is primarily intended for the following audiences:

To understand the basics in this specification you must first be familiar with JSON, which is detailed in [ RFC4627 ]. You must also understand the JSON-LD Syntax [ JSON-LD ], which is the base syntax used by all of the algorithms in this document. To understand the API and how it is intended to operate in a programming environment, it is useful to have working knowledge of the JavaScript programming language [ ECMA-262 ] and WebIDL [ WEBIDL ]. To understand how JSON-LD maps to RDF, it is helpful to be familiar with the basic RDF concepts [ RDF-CONCEPTS RDF11-CONCEPTS ].

2. Features

This section is non-normative.

The JSON-LD Syntax specification [ JSON-LD ] outlines a language syntax that may be used to express Linked Data in JSON. Often, Because there is more than one way to express Linked Data using this syntax, it is often useful to be able to transform JSON-LD documents so that they may be more easily processed consumed by specific applications.

The way JSON-LD allows Linked Data to be expressed in various programming environments. a way that is specifically tailored to a particular person or application is by providing a context . By providing a context , JSON data can be expressed in a way that is a natural fit for a particular person or application whilst also indicating how the data should be understood at a global scale. In order for people or applications to share data that was created using a context that is different from their own, a JSON-LD processor must be able to transform a document from one context to another. Instead of requiring JSON-LD processors to write specific code for every imaginable context switching scenario, it is much easier to specify a single algorithm that can remove any context . Similarly, another algorithm can be specified to subsequently apply any context . These two algorithms represent the most basic transformations of JSON-LD documents. They are referred to as expansion and compaction , respectively.

There are four major types of transformation that are discussed in this document: expansion, compaction, flattening, and RDF conversion.

2.1 Expansion

This section is non-normative.

Software algorithms are easiest to write when the data The algorithm that they are processing have removes context is called expansion . Before performing any other transformations on a regular form. Since information can be represented by JSON-LD in a variety of different ways, transforming document, it is easiest to remove any context from it, localizing all information, and to make data structures more regular.

To get an idea of these methods into a uniform structure allows how context and data structuring affects the developer to simplify their processing code. For example, note same data, here is an example of JSON-LD that the following input uses only term terms s and is fairly compact:

{ "@context": { "name": "http://xmlns.com/foaf/0.1/name", "homepage": { "@id": "http://xmlns.com/foaf/0.1/homepage", "@type": "@id" } }, "@id": "http://me.markus-lanthaler.com/", "name": "Markus Lanthaler", "homepage": "http://www.markus-lanthaler.com/"
Example 1: Sample JSON-LD document
{
  "@context": {
    "name": "http://xmlns.com/foaf/0.1/name",
    "homepage": {
      "@id": "http://xmlns.com/foaf/0.1/homepage",
      "@type": "@id"
    }
  },
  "@id": "http://me.markus-lanthaler.com/",
  "name": "Markus Lanthaler",
  "homepage": "http://www.markus-lanthaler.com/"

}

The next input example uses one IRI to express a property, property and array to encapsulate another, but leaves the rest of the information untouched.

{ "@context": { "homepage": { "@id": "http://xmlns.com/foaf/0.1/homepage", "@type": "@id" } }, "@id": "http://me.markus-lanthaler.com/", "": "Markus Lanthaler", "homepage": "http://www.markus-lanthaler.com/"
Example 2: Sample JSON-LD document using a IRI instead of a term to express a property
{
  "@context": {
    "website": "http://xmlns.com/foaf/0.1/homepage"

  },
  "@id": "http://me.markus-lanthaler.com/",
  "http://xmlns.com/foaf/0.1/name": "Markus Lanthaler",
  "website": { "@id": "http://www.markus-lanthaler.com/" }
}

While Note that both inputs are valid JSON-LD, writing a program to handle every permutation of possible inputs can be difficult, especially when JSON-LD and both represent the incoming same information. The difference is in their context could change as well. To information and in the data structures used. A JSON-LD processor can remove context and ensure that the data can be given a is more uniform structure, JSON-LD introduces the notion of expansion. regular by employing expansion .

Expansion performs has two important operations. The first is to expand goals: removing any contextual information from the document, and ensuring all values that represent IRIs are represented in a regular form. These goals are accomplished by expanding all properties to absolute IRIs . The second is to express and by expressing all values in arrays in expanded form . Expanded form is the most verbose and regular way of expressing of values in JSON-LD; all contextual information from the document is instead stored locally with each value. Running the Expansion algorithm ( expand operation) against the examples provided above results in the following output:

[ { "@id": "http://me.markus-lanthaler.com/", "http://xmlns.com/foaf/0.1/name": [ { "@value": "Markus Lanthaler" } ], "http://xmlns.com/foaf/0.1/homepage": [ { "@id": "http://www.markus-lanthaler.com/" } ] }
Example 3: Expanded sample document
[
  {
    "@id": "http://me.markus-lanthaler.com/",
    "http://xmlns.com/foaf/0.1/name": [
      { "@value": "Markus Lanthaler" }
    ],
    "http://xmlns.com/foaf/0.1/homepage": [
      { "@id": "http://www.markus-lanthaler.com/" }
    ]
  }

]

Note that in the output above all context definitions have been removed, all terms and prefixes compact IRIs have been expanded to absolute IRIs , and all JSON-LD values are expressed in arrays in expanded form . While the output is more verbose and difficult for a human to read, it is easier for establishes a software program to process baseline that makes JSON-LD processing easier because of its very regular structure.

2.2 Compaction

This section is non-normative.

While expansion expands removes context from a given input as much as possible, compaction performs input, compaction's primary function is to perform the opposite operation: it expresses to express a given input as succinctly as possible. In contrast to expansion which is meant according to produce something a particular context . Compaction applies a context that specifically tailors the way information is easy to process by software programs, compaction is meant to produce something expressed for a particular person or application. This simplifies applications that is easy consume JSON or JSON-LD by expressing the data in application-specific terms, and it makes the data easier to read by software developers. humans.

Compaction uses a developer-supplied context to compress shorten IRIs to terms or compact IRIs and JSON-LD values expressed in expanded form to simple values such as strings and or numbers .

For example, assume the following expanded JSON-LD input document:

[ { "@id": "http://me.markus-lanthaler.com/", "http://xmlns.com/foaf/0.1/name": [ { "@value": "Markus Lanthaler" } ], "http://xmlns.com/foaf/0.1/homepage": [ { "@id": "http://www.markus-lanthaler.com/" } ] }
Example 4: Expanded sample document
[
  {
    "@id": "http://me.markus-lanthaler.com/",
    "http://xmlns.com/foaf/0.1/name": [
      { "@value": "Markus Lanthaler" }
    ],
    "http://xmlns.com/foaf/0.1/homepage": [
      { "@id": "http://www.markus-lanthaler.com/" }
    ]
  }

]

Additionally, assume the following developer-supplied JSON-LD context :

{ "@context": { "name": "http://xmlns.com/foaf/0.1/name", "homepage": { "@id": "http://xmlns.com/foaf/0.1/homepage", "@type": "@id" } }
Example 5: JSON-LD context
{
  "@context": {
    "name": "http://xmlns.com/foaf/0.1/name",
    "homepage": {
      "@id": "http://xmlns.com/foaf/0.1/homepage",
      "@type": "@id"
    }
  }

}

Running the Compaction Algorithm ( compact operation) given the context supplied above against the JSON-LD input document provided above would result in the following output:

{ "@context": { "name": "http://xmlns.com/foaf/0.1/name", "homepage": { "@id": "http://xmlns.com/foaf/0.1/homepage", "@type": "@id" } }, "@id": "http://me.markus-lanthaler.com/", "name": "Markus Lanthaler", "homepage": "http://www.markus-lanthaler.com/"
Example 6: Compacted sample document
{
  "@context": {
    "name": "http://xmlns.com/foaf/0.1/name",
    "homepage": {
      "@id": "http://xmlns.com/foaf/0.1/homepage",
      "@type": "@id"
    }
  },
  "@id": "http://me.markus-lanthaler.com/",
  "name": "Markus Lanthaler",
  "homepage": "http://www.markus-lanthaler.com/"

}

Note that all IRIs have been compacted to terms as specified in the context , which consequently has been injected into the output. While compacted output is most useful to humans, it can often is also be used to generate structures that are easy to program against. Compaction enables developers to map any expanded document into an application-specific compacted document. While the context provided above mapped http://xmlns.com/foaf/0.1/name http://xmlns.com/foaf/0.1/nam to name , it could have also have been mapped to any other term provided by the developer.

2.3 Flattening

This section is non-normative.

While expansion ensures that a document is in a uniform structure, flattening goes a step further and ensures to ensure that also the shape of the data is deterministic. In expanded documents documents, the properties of a single node may still be spread across a number of different JSON objects . By flattening a document, all properties of a node are collected in a single JSON object and all blank nodes are labeled with a blank node identifier . Often this This may drastically simplifies simplify the code required to process JSON-LD data. data in certain applications.

For example, assume the following JSON-LD input document:

{ "@context": { "name": "http://xmlns.com/foaf/0.1/name", "knows": "http://xmlns.com/foaf/0.1/knows" }, "@id": "http://me.markus-lanthaler.com/", "name": "Markus Lanthaler", "knows": [ { "name": "Manu Sporny", "knows": { "@id": "http://greggkellogg.net/foaf#me" } }, { "@id": "http://greggkellogg.net/foaf#me", "name": "Gregg Kellogg" } ]
Example 7: Sample JSON-LD document
{
  "@context": {
    "name": "http://xmlns.com/foaf/0.1/name",
    "knows": "http://xmlns.com/foaf/0.1/knows"
  },
  "@id": "http://me.markus-lanthaler.com/",
  "name": "Markus Lanthaler",
  "knows": [
    {
      "name": "Dave Longley"
    }
  ]

}

Running the Flattening Algorithm algorithm ( flatten operation) with a context set to null to prevent compaction returns the following document:

[ { "@id": "http://me.markus-lanthaler.com/", "http://xmlns.com/foaf/0.1/name": [ { "@value": "Markus Lanthaler" } ], "http://xmlns.com/foaf/0.1/knows": [ { "@id": "_:t0" }, { "@id": "http://greggkellogg.net/foaf#me" } ] }, { "@id": "_:t0", "http://xmlns.com/foaf/0.1/name": [ { "@value": "Manu Sporny" } ], "http://xmlns.com/foaf/0.1/knows": [ { "@id": "http://greggkellogg.net/foaf#me" } ] }, { "@id": "http://greggkellogg.net/foaf#me", "http://xmlns.com/foaf/0.1/name": [ { "@value": "Gregg Kellogg" } ] }
Example 8: Flattened sample document in expanded form
[
  {
    "@id": "_:t0",
    "http://xmlns.com/foaf/0.1/name": [
      { "@value": "Dave Longley" }
    ]
  },
  {
    "@id": "http://me.markus-lanthaler.com/",
    "http://xmlns.com/foaf/0.1/name": [
      { "@value": "Markus Lanthaler" }
    ],
    "http://xmlns.com/foaf/0.1/knows": [
      { "@id": "_:t0" }
    ]
  }

]

Note how in the output above all properties of a node are collected in a single JSON object and how the blank node representing "Manu Sporny" "Dave Longley" has been assigned the blank node identifier _:t0 .

To make it easier for humans to read such or for certain applications to process it, a flattened document can be compacted by passing a context. Using the same context as the input document, the flattened and compacted document looks as follows:

{ "@context": { "name": "http://xmlns.com/foaf/0.1/name", "knows": "http://xmlns.com/foaf/0.1/knows" }, "@graph": [ { "@id": "http://me.markus-lanthaler.com/", "name": "Markus Lanthaler", "knows": [ { "@id": "_:t0" }, { "@id": "http://greggkellogg.net/foaf#me" } ] }, { "@id": "_:t0", "name": "Manu Sporny", "knows": { "@id": "http://greggkellogg.net/foaf#me" } }, { "@id": "http://greggkellogg.net/foaf#me", "name": "Gregg Kellogg" } ]
Example 9: Flattened and compacted sample document
{
  "@context": {
    "name": "http://xmlns.com/foaf/0.1/name",
    "knows": "http://xmlns.com/foaf/0.1/knows"
  },
  "@graph": [
    {
      "@id": "_:t0",
      "name": "Dave Longley"
    },
    {
      "@id": "http://me.markus-lanthaler.com/",
      "name": "Markus Lanthaler",
      "knows": { "@id": "_:t0" }
    }
  ]

}

Please note that the flattened and compacted result will always explicitly designate designates the default graph by the @graph member in the top-level JSON object . Compaction optimizes that member away if its value contains just one item.

2.4 RDF Conversion

This section is non-normative.

JSON-LD can be used to serialize data expressed in RDF as described in [ RDF-CONCEPTS RDF11-CONCEPTS ]. This ensures that data can be round-tripped from and to and from any RDF syntax without any loss in the fidelity of the data. fidelity.

For example, assume the following RDF input serialized in Turtle [ TURTLE-TR TURTLE ]:

<http://me.markus-lanthaler.com/> <http://xmlns.com/foaf/0.1/name> "Markus Lanthaler" .
Example 10: Sample Turtle document
<http://me.markus-lanthaler.com/> <http://xmlns.com/foaf/0.1/name> "Markus Lanthaler" .
<http://me.markus-lanthaler.com/>
<http://xmlns.com/foaf/0.1/homepage>
<http://www.markus-lanthaler.com/>
.

Using the Convert from RDF Algorithm algorithm a developer could transform this document into expanded JSON-LD:

[ { "@id": "http://me.markus-lanthaler.com/", "http://xmlns.com/foaf/0.1/name": [ { "@value": "Markus Lanthaler" } ], "http://xmlns.com/foaf/0.1/homepage": [ { "@id": "http://www.markus-lanthaler.com/" } ] }
Example 11: Sample Turtle document converted to JSON-LD
[
  {
    "@id": "http://me.markus-lanthaler.com/",
    "http://xmlns.com/foaf/0.1/name": [
      { "@value": "Markus Lanthaler" }
    ],
    "http://xmlns.com/foaf/0.1/homepage": [
      { "@id": "http://www.markus-lanthaler.com/" }
    ]
  }

]

Note that the output above could easily be compacted using the technique outlined in the previous section. It is also possible to transform the JSON-LD document back to RDF using the Convert to RDF Algorithm algorithm .

3. Conformance

All examples and notes as well as sections marked as non-normative in this specification are non-normative. Everything else in this specification is normative.

The keywords must MUST , must not MUST NOT , required REQUIRED , should SHOULD , should not SHOULD NOT , recommended RECOMMENDED , may MAY , and optional OPTIONAL in this specification are to be interpreted as described in [ RFC2119 ].

There are two classes of products that can claim conformance to this specification: JSON-LD Implementations and JSON-LD Processors .

A conforming JSON-LD Implementation is a system capable of transforming JSON-LD documents according the algorithms defined in this specification.

A conforming JSON-LD Processor is a conforming JSON-LD Implementation that exposes the application programming interface Application Programming Interface (API) defined in this specification. It MUST implement the json-ld-1.0 processing mode (for further details, see the processingMode option of JsonLdOptions ).

The algorithms in this specification are generally written with more concern for clarity than over efficiency. Thus, JSON-LD Implementations and Processors may implement the algorithms given in this specification in any way desired, so long as the end result is indistinguishable from the result that would be obtained by the specification's algorithms.

This specification does not define how JSON-LD Implementations or Processors handle non-conforming input documents. This implies that JSON-LD Implementations or Processors must not MUST NOT attempt to correct malformed IRIs or language tags; however, they may MAY issue validation warnings. IRIs are not modified other than converted between relative and absolute IRIs .

Note

Implementers can partially check their level of conformance to this specification by successfully passing the test cases of the JSON-LD test suite [ JSON-LD-TESTS ]. Note, however, that passing all the tests in the test suite does not imply complete conformance to this specification. It only implies that the implementation conforms to aspects tested by the test suite.

4. General Terminology

This document uses the following terms as defined in JSON [ RFC4627 ]. Refer to the JSON Grammar section in [ RFC4627 ] for formal definitions.

JSON object
An object structure is represented as a pair of curly brackets surrounding zero or more key-value pairs. A key is a string . A single colon comes after each key, separating the key from the value. A single comma separates a value from a following key. In contrast to JSON, in JSON-LD the keys in an object must be unique.
array
An array structure is represented as square brackets surrounding zero or more values (or elements). Elements are separated by commas. In JSON, an array is an ordered sequence of zero or more values. While JSON-LD uses the same array representation as JSON, the collection is unordered by default. While order is preserved in regular JSON arrays, it is not in regular JSON-LD arrays unless specific markup is provided (see ).
string
A string is a sequence of zero or more Unicode characters, wrapped in double quotes, using backslash escapes (if necessary). A character is represented as a single character string.
number
A number is similar to that used in most programming languages, except that the octal and hexadecimal formats are not used and that leading zeros are not allowed.
true and false
Values that are used to express one of two possible boolean states.
null
The null value. A key-value pair in the @context where the value, or the @id of the value, is null explicitly decouples a term's association with an IRI . A key-value pair in the body of a JSON-LD document whose value is null has the same meaning as if the key-value pair was not defined. If @value , @list , or @set is set to null in expanded form, then the entire JSON object is ignored.

Furthermore, the following terminology is used throughout this document:

keyword
A JSON key that is specific to JSON-LD, specified in the JSON-LD Syntax specification [ JSON-LD ] in the section titled Syntax Tokens and Keywords .
context
A a set of rules for interpreting a JSON-LD document as specified in The Context of the [ JSON-LD ] specification.
JSON-LD document
A JSON-LD document is a serialization of a collection of JSON-LD graphs and comprises exactly one default graph and zero or more named graphs .
named graph
A named graph is a pair consisting of an IRI or blank node (the graph name ) and a JSON-LD graph .
default graph
The default graph is the only graph in a JSON-LD document which has no graph name .
JSON-LD graph
A labeled directed graph, i.e., a set of nodes connected by edges , as specified in the Data Model section of the JSON-LD syntax specification [ JSON-LD ].
edge
Every edge has a direction associated with it and is labeled with an IRI or a blank node identifier . Within the JSON-LD syntax these edge labels are called properties . Whenever possible, an edge should be labeled with an IRI .
node
Every node is an IRI , a blank node , a JSON-LD value , or a list .
IRI
An IRI (Internationalized Resource Identifier) is a string that conforms to the syntax defined in [ RFC3987 ].
absolute IRI
An absolute IRI is defined in [ RFC3987 ] containing a scheme along with a path and optional query and fragment segments.
relative IRI
A relative IRI is an IRI that is relative some other absolute IRI ; in the case of JSON-LD this is the base location of the document.
blank node
A node in a JSON-LD graph that does not contain a de-referenceable identifier because it is either ephemeral in nature or does not contain information that needs to be linked to from outside of the JSON-LD graph.
blank node identifier
A blank node identifier is a string that can be used as an identifier for a blank node within the scope of a JSON-LD document. Blank node identifiers begin with _: .
JSON-LD value
A JSON-LD value is a string , a number , true or false , a typed value , or a language-tagged string .
typed value
A typed value consists of a value, which is a string, and a type, which is an IRI .
language-tagged string
A language-tagged string consists of a string and a non-empty language tag as defined by [ BCP47 ]. The language tag must be well-formed according to section section 2.2.9 of [ BCP47 ], and must be is normalized to lowercase.
list
A list is an ordered sequence of IRIs , blank nodes , and JSON-LD values .

5. Algorithms All algorithms described in this section are intended to operate on language-native data structures. That is, the serialization to a text-based JSON document isn't required as input or output to any of these algorithms and language-native data structures must be used where applicable. 5.1 Algorithm Terms

active graph
The name of the currently active graph that the processor should use when processing.
active subject
The currently active subject that the processor should use when processing.
active property
The currently active property that the processor should use when processing. The active property is represented in the original lexical form, which is used for finding type mappings in the active context . active object The currently active object or keyword that the processor should use when processing.
active context
A context that is used to resolve term terms s while the processing algorithm is running. The active context is the context contained within the processor state .
local context
A context that is specified within a JSON object , specified via the @context keyword .
processor state The processor state , which includes the active context , active subject , and active property . The processor state is managed as a stack with elements from the previous processor state copied into a new processor state when entering a new JSON object . JSON-LD input
The JSON-LD data structure that is provided as input to the algorithm.
JSON-LD output The JSON-LD data structure that is produced as output by the algorithm. term
A term is a short word defined in a context that may be expanded to an IRI
compact IRI
A compact IRI is has the form of prefix : suffix and is used as a way of expressing an IRI without needing to define separate term definitions for each IRI contained within a common vocabulary identified by prefix .
node object
A node object represents zero or more properties of a node in the JSON-LD graph serialized by the JSON-LD document. A JSON object is a node object if it exists outside of the JSON-LD context and:
  • it does not contain the @value , @list , or @set keywords, or
  • it is not the top-level top-most JSON object in the JSON-LD document containing the consisting of no other members than @graph keyword. and @context .
value object
A value object is a JSON object that has an @value member.
list object
A list object is a JSON object that has a an @list member.
set object
A set object is a JSON object that has an @set member.
scalar
A scalar is either a JSON string , number , true , or false .
quad RDF subject
A subject as specified by [ RDF11-CONCEPTS ].
RDF predicate
A predicate as specified by [ RDF11-CONCEPTS ].
RDF object
An object as specified by [ RDF11-CONCEPTS ].
RDF triple
A triple as specified by [ RDF-CONCEPTS RDF11-CONCEPTS ].
RDF dataset
A dataset as specified by [ RDF11-CONCEPTS ] augmented with a a fourth component, representing a graph name collection of RDF graphs .

6. Context Processing Algorithms

5.2 6.1 Expansion Context Processing Algorithm

The algorithm takes three input variables: an When processing a JSON-LD data structure, each processing rule is applied using information provided by the active context , . This section describes how to produce an active property , and an element to be expanded. To begin, the context .

The active context is set to contains the result of performing, Context Processing on active term definitions which specify how properties and values have to be interpreted as well as the passed current base IRI expandContext , the vocabulary mapping and the default language . Each term definition consists of an , IRI mapping , a boolean flag reverse property , an optional type mapping or empty if expandContext language mapping , and an optional container mapping . A term definition can not only be used to map a term to an IRI , but also to map a term to a keyword , in which case it is null referred to as a keyword alias .

When processing, the active context is initialized without any term definitions , vocabulary mapping , or default language . If a local context is encountered during processing, a new active property context is set created by cloning the existing active context . Then the information from the local context is merged into the new active context . Given that local contexts may contain references to null , and remote contexts, this includes their retrieval.

General Solution

element This section is set to non-normative.

First we prepare a new active context result by cloning the JSON-LD input current active context . This algorithm expects Then we normalize the JSON-LD input form the passed local context to an array . Local contexts may be in the form of a well-formed JSON-LD document as defined JSON object , a string , or an array containing a combination of the two. Finally we process each context contained in [ JSON-LD the local context ]. array as follows.

If element context is a scalar string , expand it according represents a reference to a remote context. We dereference the Value Expansion remote context and replace context algorithm, passing copies with the value of the active @context key of the top-level object in the retrieved JSON-LD document. If there's no such key, an invalid remote context has been detected. Otherwise, we process context by recursively using this algorithm ensuring that there is no cyclical reference.

If context is a JSON object , we first update the base IRI , the vocabulary mapping , and active property the default language by processing three specific keywords: @base , @vocab , and return. If element is null @language . These are handled before any other keys in the local context because they affect how the other keys are processed.

Then, for every other key in local context , return. If element we update the term definition in result . Since term definitions in a local context may themselves contain terms or compact IRIs , we may need to recurse. When doing so, we must ensure that there is no cyclical dependency, which is an array error. After we have processed any term definition dependencies, we update the current term definition , initialize an empty array which may be a keyword alias .

Finally, we return result . Expand each item by recursively using this algorithm, passing copies of as the new active context and active property . If the

Algorithm

This algorithm specifies how a new active property's container mapping context is set to @list updated with a local context . The algorithm takes three input variables: an active context , a local context , and the expanded item is an array or a list object trigger a LIST_OF_LISTS_DETECTED error. remote contexts which is used to detect cyclical context inclusions. If the expanded item remote contexts is null , drop it. Otherwise, if the expanded item not passed, it is initialized to an empty array , merge its entries with result's entries. .

  1. Otherwise, append item to Initialize result . Finally, set element to the result and return. of cloning active context .
  2. Otherwise, element must be an object. If element has a @context member, update the active local context according is not an array , set it to the steps outlined in Context Processing and remove the @context member. Initialize an empty JSON object array result and containing only local context .
  3. then process For each property and value item context in element ordered by property as follows: local context :
    1. If the active context contains a property generator for property set expanded property to its IRIs is null , otherwise set it to the result of expanding property according to the steps outlined in IRI Expansion a newly-initialized active context (passing true for the vocabRelative flag). If expanded property is null , skip the current property - value pair and continue to with the next property - value pair in element . context .
    2. If expanded property context is a keyword string , process it as follows:
      1. If expanded property equals @id , set the @id member of result Set context to the result of expanding resolving value according against the base IRI Expansion algorithm (passing true for the documentRelative flag). If value which is not established as specified in section 5.1 Establishing a string Base URI trigger an INVALID_ID_VALUE error. If expanded property equals @type , set the @type member of result to [ RFC3986 ]. Only the result basic algorithm in section 5.2 of expanding value according the [ IRI Expansion algorithm RFC3986 (passing true for both the documentRelative and the vocabRelative flag). If value ] is used; neither a string Syntax-Based Normalization nor an array Scheme-Based Normalization of strings are performed. Characters additionally allowed in IRI references are treated in the same way that unreserved characters are treated in URI references, per section 6.5 trigger an INVALID_TYPE_VALUE error. Empty arrays of [ RFC3987 are ignored. ].
      2. If expanded property equals @value , set the @value member of result to value . If value context is neither in the remote contexts array, a scalar nor null trigger an INVALID_VALUE_OBJECT_VALUE recursive context inclusion error. error has been detected and processing is aborted; otherwise, add context to remote contexts .
      3. If expanded property equals @language , set Initialize context no base to the @language member of result to of cloning the lowercased value . If value is not a string , trigger an INVALID_LANGUAGE_VALUE error. active context .
      4. If expanded property equals @annotation , set Remove the @annotation member of result to value . If value is not a string base IRI trigger an INVALID_ANNOTATION_VALUE error. of context no base .
      5. Dereference context . If expanded property equals the dereferenced document has no top-level JSON object with an @set @context or @list , member, an invalid remote context has been detected and processing is aborted; otherwise, set context to the expanded property member value of result that member.
      6. Set context to the result of expanding value by recursively using calling this algorithm, passing copies of the context no base for active context , context for local context , and active property . remote contexts .
      7. If expanded property equals @graph , context has no base IRI but result does, set the @graph member base IRI of result context to the result of expanding value by recursively using this algorithm, passing copies one of the active context and @graph as active property . result .
      8. Continue Overwrite result with context and continue with the next property - value pair from element . context .
    3. If expanded property context is not a JSON object , an absolute IRI ,i.e., it doesn't contain a colon, continue with the next member from element . Otherwise, if property's container mapping invalid local context is set to @language Initialize a new empty array language map values . error has been detected and processing is aborted.
    4. Process each key - val pair of value ordered by key as follows: If val is not context has an array, transform it to one. For each item of val , construct a new JSON object consisting of two members: @value @base set to key:
      Issue 223 : Feature at risk

      This feature is at risk as the currently processed item and fact that a document may have multiple base IRIs is potentially confusing for developers. It is also being discussed whether relative IRIs are allowed as values of @language @base set to or whether the lowercased key . If val is not a empty string , trigger a LANGUAGE_MAP_INVALID_VALUE error. Otherwise append the object to language map values . Set value should be used to language map values . Otherwise, if property's container mapping is set explicitly specify that there isn't a base IRI , which could be used to @annotation ensure that relative IRIs remain relative when expanding.

      1. Initialize a new empty array annotation map values . Process each key - val pair of value ordered by key as follows: If val is not an array, transform it to one. Expand val by recursively using this algorithm, passing copies of the active context and active property . Add to each item of val a member value associated with the @annotation @base set to key if no such member exists yet and append the resulting JSON object to annotation map values . Set value to annotation map values . key.
      2. Otherwise, expand If value by recursively using this algorithm, passing copies of is null , remove the active context base IRI and property as active property . of result .
      3. If the expanded Otherwise, if value equals null is an absolute IRI , continue with the next property - value pair from element . If property's container mapping base IRI of result is set to @list and value . If it is either not an JSON object or a JSON object without absolute IRI , an @list member, replace value with a JSON object invalid base IRI with an @list member whose value is set to value (wrapped in an array if it error has been detected and processing is not already one). aborted.
    5. If expanded property is context has an array , @vocab key:
      1. label all blank nodes in Initialize value to the value associated with blank node identifiers by using the Label Blank Nodes Algorithm . @vocab key.
      2. Then, for each iri of expanded property merge a copy of If value into the iri member of the is null , remove any vocabulary mapping from result JSON object . .
      3. Otherwise, merge if value into is an absolute IRI , the iri member vocabulary mapping of the result JSON object . Set element to result and numProperties is set to the number of members of result . value . If element has it is not an @annotation member, decrease numProperties by 1. If element has absolute IRI , an @value invalid vocab mapping member, decrease numProperties by 1. If element error has an @language member, decrease numProperties by 1 been detected and check that the value of the @value member processing is a string. If not, trigger an INVALID_LANGUAGE_TAGGED_STRING error. aborted.
    6. Otherwise, if element If context has an @type @language member, decrease numProperties by 1 and check that key:
      1. Initialize value to the value of associated with the @type member is a string. If not, trigger an INVALID_TYPED_VALUE @language error. key.
      2. If numProperties value is greater than 0, trigger an INVALID_VALUE_OBJECT error. null , remove any default language from result .
      3. If the Otherwise, if value of the @value member equals null is string , the default language of result is set element to null . Return. If element has an @type member whose lowercased value . If it is not an array a string , transform it to an array . If element has an @list or @set invalid default language member error has been detected and numProperties processing is greater than 1, trigger an INVALID_SET_OR_LIST_OBJECT error. aborted.
    7. Otherwise, if element has an @set member, set element Create a JSON object defined to the value use to keep track of that member. whether or not a term has already been defined or currently being defined during recursion.
    8. Otherwise, if element has just an For each key - value pair in context where key is not @base , @vocab , or @language member, set element to null. , invoke the Create Term Definition algorithm , passing result for active context , context for local context , key , and defined .
  4. Return result .

6.2 Create Term Definition

If, after the This algorithm outlined above is run, called from the resulting element is an JSON object Context Processing algorithm with just a @graph member, element is set to create a term definition in the value of @graph 's value. Finally, if element is active context for a JSON object , it is wrapped into an array term being processed in a local context .

General Solution

5.3 Context Processing

Processing of JSON-LD data structure is managed recursively. During processing, each rule This section is applied using information provided by the active context . non-normative.

The active Term definitions are created by parsing the information in the given local context contains for the active given term definitions which specify how properties and values have to be interpreted as well as the current vocabulary mapping and . If the default language . Each given term definition consists of an is a compact IRI mapping and optionally a type mapping from terms to datatypes or language mapping from terms to language codes, and a container mapping . If , it may omit an IRI mapping maps a by depending on its prefix having its own term to multiple IRIs it is said to be a property generator . definition . If a local context is encountered, information from the local context prefix is merged into a key in the active context . A local context , then its term definition is identified within must first be created, through recursion, before continuing. Because a JSON object term definition having can depend on other term definitions , a @context member with mechanism must be used to detect cyclical dependencies. The solution employed here uses a string , array map, defined , that keeps track of whether or not a JSON object term value. has been defined or is currently in the process of being defined. This map is checked before any recursion is attempted.

This algorithm specifies how After all dependencies for a term have been defined, the active rest of the information in the local context for the given term is updated with a local context taken into account, creating the appropriate IRI mapping , container mapping , and type mapping or language mapping for the term .

Algorithm

The algorithm takes three input variables: has four required inputs which are: an active context , a local context , a term , and an array of already included remote contexts remoteContexts . To begin, remoteContexts is initialized to an empty array. a map defined .

All calls of
  1. If defined contains the key term and the associated value is true (indicating that the term definition has already been created), return. Otherwise, if the value is false , a cyclic IRI Expansion algorithm mapping pass error has been detected and processing is aborted.
  2. Set the value specified in the algorithm along associated with defined 's term key to false . This indicates that the active context , the currently term definition is now being processed local context , and true for the vocabRelative flag. created but is not yet complete.
  3. If the local context Since keywords is cannot be overridden, term must not an array, transform it to one. be a keyword . Otherwise, a keyword redefinition error has been detected and processing is aborted.
  4. Process each item Remove any existing term definition for term in active context of .
  5. Initialize value to the value associated with the key term in local context as follows: .
  6. If context equals value is null or value is a JSON object containing the key-value pair @id - null , reset set the term definition in active context and continue with to null , set the next item. value associated with defined 's key term to true , and return.
  7. If context Otherwise, if value is a string :
    1. Expand context according value by setting it to the result of using the IRI Expansion . algorithm , passing active context , value , true for vocab , true for document relative , local context , and defined .
    2. If context value is in the remoteContexts array, raise @context , an RECURSIVE_CONTEXT_INCLUSION invalid keyword alias error. Otherwise, add context to remoteContexts . error has been detected and processing is aborted.
    3. Dereference Set the IRI mapping for the term definition for term in active context . to value , set the value associated with defined 's key term to true , and return.
  8. If the resulting document is a JSON document consisting of Otherwise, value must be a top-level JSON object , if not, an invalid term definition that has a @context member recursively invoke this algorithm passing error has been detected and processing is aborted.
  9. Create a copy of active context new term definition , the definition .
  10. If value of contains the key @context member as local context , and a copy of the remoteContexts array. Relative IRIs are expanded using the remote context's IRI . Otherwise raise @reverse :
    1. If value contains an @id , an @type , or an @language , member, an INVALID_REMOTE_CONTEXT invalid reverse property error. error has been detected and processing is aborted.
    2. Continue If the value associated with the next item from context . If context @reverse key is not a JSON object string , raise an INVALID_LOCAL_CONTEXT invalid IRI mapping error. error has been detected and processing is aborted.
    3. Otherwise, if set the IRI mapping of definition to the result of using the IRI Expansion algorithm , passing active context is an JSON object , perform the following steps: If context has a value associated with the @vocab @reverse member: if its key for value , true for vocab , true for document relative , local context , and defined . If the result is neither not an absolute IRI , i.e., it does not contain a contains no colon ( : ), nor null , trigger an INVALID_VOCAB_MAPPING invalid IRI mapping error; otherwise set error has been detected and processing is aborted.
    4. Set the active context's vocabulary type mapping of definition to its value and remove the @vocab member from context . @id .
    5. If context has a @language member: if its value is neither a string nor null , trigger contains an INVALID_DEFAULT_LANGUAGE @container error; otherwise member, set the active context's default language container mapping of definition to its value and remove the @language @index member from context . For each other key - value pair in context perform the following steps: Remove if that is the key - value pair from context . of the @container member; otherwise an invalid reverse property error has been detected (reverse properties only support index-containers) and processing is aborted.
    6. If key is a JSON-LD keyword , continue with Set the next key - value pair. reverse property flag of definition to true .
    7. If value equals null , replace Set the term definition for key of term in the active context to definition and the value associated with an IRI mapping set defined 's key term to null true and continue with return.
  11. Set the next key - value pair. reverse property flag of definition to false .
  12. If value contains the key @id :
    1. If the value associated with the @id key is not a string , expand it according to the an invalid IRI Expansion algorithm mapping error has been detected and replace the term definition for key in processing is aborted.
    2. Otherwise, set the active context with an IRI mapping set of definition to the expanded result of using the IRI Expansion algorithm , passing active context , the value . Continue associated with the next @id key - for value pair. , true for vocab , true for document relative , local context , and defined .
  13. If value is not Otherwise if the term contains a JSON object , trigger an INVALID_TERM_DEFINITION colon ( : error ):
    1. If term definition is a compact IRI for with a prefix that is a key exists in the local context a dependency has been found. Use this algorithm recursively passing active context , remove it. Initialize a new, empty term definition local context , the prefix definition . as term , and defined .
    2. If value term 's prefix has an @id member with a value val : if val is null term definition in active context , set the IRI mapping of definition to val . if val is an array , process each item in the array: if item is a string expand it according result of concatenating the value associated with the prefix 's IRI Expansion algorithm . otherwise, raise an INVALID_PROPERTY_GENERATOR error. if val is an array , lexicographically sort val mapping and set definition to val . the term 's suffix .
    3. Otherwise, if val term is a string , expand it according an absolute IRI . Set the IRI Expansion algorithm mapping and set of definition to val . term .
  14. If Otherwise, if active context has a vocabulary mapping , the IRI mapping of definition is set to null or a keyword , store the definition as result of concatenating the term definition for key in value associated with the active context vocabulary mapping and continue with the next key - value pair from context . Otherwise, set the term . If it does not have a vocabulary mapping , an invalid IRI mapping of definition to the result of expanding key according the IRI Expansion algorithm . error been detected and processing is aborted.
  15. If value has an contains the key @type member with a :
    1. Initialize type to the value val and val is not associated with the @type key, which must be a string or does not expand to . Otherwise, an absolute IRI invalid type mapping error has been detected and processing is aborted.
    2. Set type to the result of using the IRI Expansion algorithm , raise an INVALID_TYPE_MAPPING error. Otherwise set passing active context , type for value , true for vocab , true for document relative , local context , and defined . If the expanded type is neither @id , nor @vocab , nor an absolute IRI , an invalid type mapping of definition to the expanded val . Otherwise, if value has an @language member with a value val that error has been detected and processing is a string or null , set aborted.
    3. Set the language type mapping of for definition to the lowercased val . If val is neither a string nor null , raise an INVALID_LANGUAGE_MAPPING error. type .
  16. f If value has an contains the key @container member with a :
    1. Initialize container to the value val that equals associated with the @container key, which must be either @list , @set , or @annotation @index , set or @language . Otherwise, an invalid container mapping error has been detected and processing is aborted.
    2. Set the container mapping of definition to val . container .
  17. If val is value contains the key @language and does not one of those values, raise contain the key @type :
    1. Initialize language to the value associated with the @language key, which must be either null or a string . Otherwise, an INVALID_CONTAINER_MAPPING invalid language mapping error. error has been detected and processing is aborted.
    2. If language is a string set it to lowercased language . Set the language mapping of definition to language .
  18. Set the term definition of term in active context to definition and set the value associated with defined 's key term to true .

5.4 6.3 IRI Expansion

In JSON-LD documents documents, some keys and some values are evaluated to produce an IRI may represent IRIs . This section defines an algorithm for transforming strings representing a string that represents an IRI into an absolute IRI or blank node identifier . It also covers transforming keyword aliases into keywords .

IRI expansion may occur during context processing or during any of the other JSON-LD algorithms. If IRI expansion occurs during context processing, then the local context that is being processed is and its related defined map from the Context Processing algorithm are passed to this algorithm. After application of this algorithm, values This allows for term definition dependencies to be processed by this via the Create Term Definition algorithm are said .

General Solution

This section is non-normative.

In order to be in expanded expand value to an absolute IRI , we must first determine if it is null , a term , a keyword alias , or some form , although this of IRI . Based on what we find, we handle the specific kind of expansion; for example, we expand a keyword alias to a keyword and a term to an absolute IRI according to its IRI mapping in the active context . While inspecting value we may also include blank node identifiers find that we need to create term definition dependencies because we're running this algorithm during context processing. We can tell whether or not we're running during context processing by checking local context against null . We know we need to create a term definition in the active context when value is a key in the local context and JSON-LD keywords the defined map does not have a key for value with an associated value of true . The defined map is used during Context Processing to keep track of which terms have already been defined or are in the process of being defined. We create a term definition by using the Create Term Definition algorithm .

Algorithm

The algorithm takes two mandatory required and four optional input variables: variables. The required inputs are an active context and a value to be expanded, an active context , expanded. The optional inputs are two flags documentRelative flags, document relative and vocabRelative vocab , that specifying whether value should can be interpreted as a relative IRI against the document's base IRI or the active context's vocabulary mapping , along with an respectively, and a local context passed and a map defined to be used when this algorithm is used in during Context Processing , and finally an array path which is used to detect cyclic IRI mappings . If not passed, the two flags are set to false and path is local context and defined are initialized to an empty array by default. The algorithm for generating an IRI is: null .

  1. If value is null or a JSON-LD keyword or null , return value as is.
  2. If a local context has been passed and value is in the path array, raise not null , it contains a CYCLIC_IRI_MAPPING error. Otherwise append key that equals value to path . If local context contains an IRI mapping for , and the value associated with the key that equals value in defined is not a property generator return true , invoke the result of recursively calling this Create Term Definition algorithm , passing the IRI of the IRI mapping as new value , the active context and , local context , path , value as term , and true for the vocabRelative flag. If the result is defined . This will ensure that a property generator , raise an PROPERTY_GENERATOR_IN_TERM_DEFINITION error. If an IRI mapping term definition exists is created for value in the active context that during Context Processing .
  3. If vocab is not a property generator true return and the active context has a term definition for value of , return the associated IRI mapping .
  4. If value contains a colon ( : ), perform the following steps: it is either an absolute IRI or a compact IRI :
    1. Split value into a prefix and suffix at the first occurrence of a colon ( : ).
    2. If prefix is not underscore ( _ ) and suffix begins does not begin with double-forward-slash ( // or prefix equals _ , return value as is. ), it may be a compact IRI :
      1. If a local context has been passed, expand prefix by recursively invoking this algorithm passing is not null , it contains a key that equals prefix as , and the value , associated with the key that equals prefix in defined is not true , invoke the Create Term Definition algorithm , passing active context and , local context , path , and true for the vocabRelative flag. If the expanded prefix contains a colon ( : ) generate as term , and return an IRI defined . This will ensure that a term definition by prepending the expanded is created for prefix to the (possibly empty) suffix using textual concatenation. in active context during Context Processing .
      2. Otherwise, if the If active context contains an IRI mapping a term definition for prefix that is not a property generator , generate and return an the result of concatenating the IRI mapping by prepending the associated with prefix and suffix .
    3. Return value as it is already an absolute IRI mapped to prefix to the (possibly empty) suffix using textual concatenation. .
  5. Otherwise, if the vocabRelative flag If vocab is set to true , and the active context contains has a vocabulary mapping , generate and return an IRI by prepending the IRI result of concatenating the vocabulary mapping to the with value using textual concatenation. .
  6. Otherwise, if the documentRelative flag document relative is true , set value to true , resolve the result of resolving value against the base IRI as per [ RFC3986 ] and return the resulting IRI . Only the basic algorithm in section 5.2 of [ RFC3986 ] is used; neither Syntax-Based Normalization nor Scheme-Based Normalization (as described in sections 6.2.2 and 6.2.3 of [ RFC3986 Scheme-Based Normalization ]) are performed. Characters additionally allowed in IRI references are treated in the same way that unreserved characters are treated in URI references, per section 6.5 of [ RFC3987 ] ].
  7. Otherwise If local context is not null and value is not an absolute IRI , an invalid IRI mapping error has been detected and processing is aborted.
  8. Otherwise, return value as is.

7. Expansion Algorithms

7.1 Expansion Algorithm

If the result of the This algorithm above is a blank node identifier , i.e., expands a string JSON-LD document, such that begins with _: , and no local all context has been passed, generated a new definitions are removed, all terms and compact IRIs are expanded to absolute IRIs , blank node identifier identifiers , or keywords before returning the final result. and all JSON-LD values are expressed in arrays in expanded form .

General Solution

5.5 Value Expansion

Some values in This section is non-normative.

Starting with its root element , we can process the JSON-LD document recursively, until we have a fully expanded result . When expanding an element , we can be expressed treat each one differently according to its type, in order to break down the problem:

  1. If the element is null , there is nothing to expand.
  2. Otherwise, if element is a compacted form . These values are required scalar , we expand it according to be expanded at times when processing JSON-LD documents. A value the Value Expansion algorithm .
  3. Otherwise, if the element is said an array , then we expand each of its items recursively and return them in a new array .
  4. Otherwise, element is a JSON object . We expand each of its keys, adding them to our result , and then we expand each value for each key recursively. Some of the keys will be terms or compact IRIs and others will be keywords or simply ignored because they do not have definitions in the context . Any IRIs will be expanded form after using the application of this algorithm. IRI Expansion algorithm .

Finally, after ensuring result is in an array , we return result .

Algorithm

The algorithm for expanding a value takes three input variables: an active context , an active property , and an element to be expanded. To begin, the active context . It is implemented as follows: set to the result of performing, Context Processing on the passed expandContext , or empty if expandContext is null , active property is set to null , and element is set to the JSON-LD input .

  1. If value element is null , return null .
  2. If element is a scalar ,
    1. If active property is null or @graph , drop the free-floating scalar by returning null .
    2. Return the result of the Value Expansion algorithm , passing the active context , active property , and element as value .
  3. If element is an array ,
    1. Initialize an empty object array, result . .
    2. For each item in element :
      1. Initialize expanded item to the result of using this algorithm recursively, passing active context , active property , and item as element .
      2. If the active property is @graph @list or the active property's type its container mapping is set to @id @list , add the expanded item must not be an array or a key-value pair list object , otherwise a list of lists error has been detected and processing is aborted.
      3. If expanded item is an array , append each of its items to result where . Otherwise, if expanded item is not null, append it to result .
    3. Return result .
  4. Otherwise element is a JSON object .
  5. If element contains the key is @id @context , set active context to the result of the Context Processing algorithm , passing active context and the value is of the @context key as local context .
  6. Initialize an empty JSON object , result of expanding .
  7. For each key and value according in element , ordered lexicographically by key :
    1. If key is @context , continue to the next key .
    2. Set expanded property to the result of using the IRI Expansion algorithm , passing active context , key for value , and true for the documentRelative flag. Then return result . vocab .
    3. Add If expanded property is null or it neither contains a key-value pair colon ( : ) nor it is a keyword , drop key by continuing to result where the next key .
    4. If expanded property is a keyword :
      1. If active property equals @value @reverse , an invalid reverse property map error has been detected and the value processing is value . aborted.
      2. If the active result has already an expanded property member, an colliding keywords error has been detected and processing is aborted.
      3. If expanded property is @id and value is not a type mapping string , add a key-value pair an invalid @id value error has been detected and processing is aborted. Otherwise, set expanded value to the result where of using the key IRI Expansion algorithm , passing active context , value , and true for document relative .
      4. If expanded property is @type and the value is neither a string nor an array of strings , an invalid type value error has been detected and processing is aborted. Otherwise, set expanded value to the result of using the IRI Expansion algorithm , passing active context , true associated with the type mapping for vocab , and true for document relative to expand the value or each of its items.
      5. If expanded property is @graph , set expanded value to the result of using this algorithm recursively passing active context , @graph for active property , and value for element .
      6. If expanded property is @value and value is not a newly generated blank node identifier scalar if the type mapping or null , an invalid value object value error has been detected and processing is aborted. Otherwise, set expanded value to a blank node identifier . value . If expanded value is null , set the @value member of result to null and continue with the next key from element . Null values need to be preserved in this case as the meaning of an @type member depends on the existence of an @value member.
      7. Otherwise, if If expanded property is @language and value is not a string , an invalid language-tagged string error has been detected and the active processing is aborted. Otherwise, set expanded value to lowercased value .
      8. If expanded property has is @index and value is not a language mapping or string , an default language invalid @index value error has been detected and processing is aborted. Otherwise, set in expanded value to value .
      9. If expanded property is @list :
        1. If active property is null or @graph , continue with the next key from element to remove the free-floating list..
        2. Otherwise, initialize expanded value to the result of using this algorithm recursively passing active context , add active property , and value for element .
        3. If expanded value is a key-value pair list object , a list of lists error has been detected and processing is aborted.
      10. If expanded property is @set , set expanded value to result where the key result of using this algorithm recursively, passing active context , active property , and value for element .
      11. If expanded property is @language @reverse and the value is the language tag associated with the language mapping not a JSON object , an invalid @reverse value or error has been detected and processing is aborted. Otherwise
        1. Initialize expanded value to the result of using this algorithm recursively, passing active context , @reverse as active property or , and value as element .
        2. If expanded value contains an @reverse member, i.e., properties that are reversed twice, execute for each of its property and item the default language following steps:
          1. If result does not have a property member, create one and set its value to an empty array .
          2. Return Append item to the value of the property member of result . .
          5.6 Label Blank Nodes Algorithm The algorithm takes a single input variable:
        3. If expanded value contains members other than @reverse :
          1. If result does not have an element @reverse member, create one and set its value to be labeled with blank node identifiers an empty JSON object .
          2. Reference the value of the @reverse member in result using the variable reverse map .
          3. For each property and items in expanded value other than @reverse :
            1. For each item in items :
              1. If element item is a value object or list object , an invalid reverse property value has been detected and processing is aborted.
              2. If reverse map has no property member, create one and initialize its value to an empty array .
              3. Append item to the value of the property member in reverse map .
        4. Continue with the next key from element .
      12. Unless expanded value is null , recursively apply this algorithm set the expanded property member of result to all its items. expanded value .
      13. Continue with the next key from element. .
    5. Otherwise, if element key 's container mapping in active context is @language and value is a JSON object with then value is expanded from a @list language map as follows:
      1. Initialize expanded value to an empty array .
      2. For each key-value pair language - language value in value , ordered lexicographically by language :
        1. If language value is not an array set it to an array containing only language value .
        2. For each item in language value :
          1. item must be a string , otherwise an invalid language map value member, recursively apply this algorithm error has been detected and processing is aborted.
          2. Append a JSON object to all items expanded value that consists of the two key-value pairs: ( @list @value member's value. - item ) and ( @language -lowercased language ).
    6. Otherwise, if element key 's container mapping in active context is @index and value is a JSON object then value is expanded from an index map as follows:
      1. Initialize expanded value to an empty array .
      2. For each key key-value pair index - index value pair in value , ordered lexicographically by key recursively apply index :
        1. If index value is not an array set it to an array containing only index value .
        2. Initialize index value to the result of using this algorithm recursively, passing active context , key as active property , and index value as element .
        3. For each item in index value :
          1. If item does not have the key @index , add the key-value pair ( @index - index ) to item .
          2. Append item to expanded value . .
    7. Otherwise, initialize expanded value to the result of using this algorithm recursively, passing active context , key for active property , and value for element .
    8. If expanded value is null , ignore key by continuing to the next key from element .
    9. If the container mapping associated to key in active context is @list and expanded value is not already a node list object , convert expanded value to a list object without by first setting it to an array containing only expanded value if it is not already an array , and then by setting it to a JSON object containing the key-value pair @id @list - expanded value .
    10. Otherwise, if the term definition associated to key indicates that it is a reverse property
      1. If result has no @reverse member, create a new one and initialize its value to an empty JSON object .
      2. Reference the value of the @id @reverse member and assign in result using the variable reverse map .
      3. If expanded value is not an array , set it to an array containing expanded value .
      4. For each item in expanded value
        1. If item is a new blank node identifier value object according the Generate Blank Node Identifier or list object , an invalid reverse property value algorithm. has been detected and processing is aborted.
        2. If reverse map has no expanded property member, create one and initialize its value to an empty array .
        3. Append item to the value of the expanded property member of reverse map .
      5.7 Generate Blank Node Identifier This algorithm
    11. Otherwise, if key is used to generate new blank node identifiers or to relabel existing blank node identifiers with not a new reverse property :
      1. If result does not have an expanded property member, create one and initialize its value to avoid collision by an empty array .
      2. Append expanded value to value of the introduction expanded property member of new ones. result .
  8. If result contains the key @value :
    1. The result must not contain any keys other than @value , @language , @type , and @index . It needs must not contain both the @language key and the @type key. Otherwise, an invalid value object error has been detected and processing is aborted.
    2. If the value of result 's @value key is null , then set result to keep null .
    3. Otherwise, if the value of result 's @value member is not a string and result contains the key @language , an identifier map , invalid language-tagged value error has been detected (only strings can be language-tagged) and processing is aborted.
    4. Otherwise, if the result has a counter , @type member and its value is not a prefix between string , an invalid typed value error has been detected and processing is aborted.
  9. Otherwise, if result contains the key @type and its executions associated value is not an array , set it to an array containing only the associated value.
  10. Otherwise, if result contains the key @set or @list :
    1. The result must contain at most one other key and that key must be able @index . Otherwise, an invalid set or list object error has been detected and processing is aborted.
    2. If result contains the key @set , then set result to generate new blank node identifiers the key's associated value.
  11. If result contains only the key @language , set result to null . The counter
  12. If active property is initialized null or @graph , drop free-floating values as follows:
    1. If result is an empty JSON object or contains the keys @value or @list , set result to null .
    2. Otherwise, if result is a JSON object whose only key is 0 @id , set result to null .
  13. Return result .

If, after the above algorithm is run, the result is a JSON object that contains only an @graph and key, set the result to the value of @graph 's value. Otherwise, if the result is null , set it to an empty array . Finally, if the result is not an array , then set the result to an array containing only the result.

7.2 Value Expansion

Some values in JSON-LD can be expressed in a compact form . These values are required to be expanded at times when processing JSON-LD documents. A value is said to be in expanded form after the application of this algorithm.

General Solution

prefix This section is non-normative.

If active property has a type mapping in the active context set to _:t @id by default. or @vocab , a JSON object with a single member @id whose values is the result of using the IRI Expansion algorithm on value is returned.

Otherwise, the result will be a JSON object containing an @value member whose value is the passed value . Additionally, an @type member will be included if there is a type mapping associated with the active property or an @language member if value is a string and there is language mapping associated with the active property .

Algorithm

The algorithm takes three required inputs: an active context , an active property , and a single input variable identifier which might be null . value to expand.

  1. If the identifier active property has a type mapping in active context that is not null @id , return a new JSON object containing a single key-value pair where the key is @id and the value is in the identifier map , return result of using the mapped identifier. IRI Expansion algorithm , passing active context , value , and true for document relative .
  2. Otherwise, generate If active property has a type mapping in active context that is @vocab , return a new blankNodeIdentifier by concatenating prefix JSON object containing a single key-value pair where the key is @id and counter . the value is the result of using the IRI Expansion algorithm , passing active context , value , true for vocab , and true for document relative .
  3. Increment counter by Otherwise, initialize result to a JSON object with an 1 . @value member whose value is set to value .
  4. If identifier is not null active property has a type mapping in active context , create add an @type member to result and set its value to the value associated with the type mapping .
  5. Otherwise, if value is a new entry string :
    1. If a language mapping is associated with active property in identifier map active context , add an @language to result and set its value to blankNodeIdentifer . the language code associated with the language mapping ; unless the language mapping is set to null in which case no member is added.
    2. Otherwise, if the active context has a default language , add an @language to result and set its value to the default language .
  6. Return blankNodeIdentifier . result .

8. Compaction Algorithms

5.8 8.1 Compaction Algorithm

This algorithm compacts a JSON-LD document, such that the given context is applied. This must result in shortening any applicable IRIs to terms or compact IRIs , any applicable keywords to keyword aliases , and any applicable JSON-LD values expressed in expanded form to simple values such as strings or numbers .

General Solution

This section is non-normative.

Starting with its root element , we can process the JSON-LD document recursively, until we have a fully compacted result . When compacting an element , we can treat each one differently according to its type, in order to break down the problem:

  1. If the element is a scalar , it is already in compacted form , so we simply return it.
  2. If the element is an array , we compact each of its items recursively and return them in a new array .
  3. Otherwise element is a JSON object . The value of each key in element is compacted recursively. Some of the keys will be compacted, using the IRI Compaction algorithm , to terms or compact IRIs and others will be compacted from keywords to keyword aliases or simply left unchanged because they do not have definitions in the context . Values will be converted to compacted form via the Value Compaction algorithm . Some data will be reshaped based on container mappings specified in the context such as @index or @language maps.

The final output is a JSON object with a @context key, if a context was given, where the JSON object is either result or a wrapper for it where result appears as the value of an (aliased) @graph key because result contained two or more items in an array .

Algorithm

The algorithm takes four five required input variables: an active context , an inverse context , an active property , and an element to be compacted. compacted, and a flag compactArrays . To begin, the active context is set to the result of performing Context Processing on the passed context , , the inverse context is set to the result of creating an inverse context from performing the Inverse Context Creation algorithm on active context , the active property is set to null , and element is set to the result of performing the Expansion Algorithm algorithm on the JSON-LD input , and, if not passed, compactArrays is set to true .

  1. If element is a scalar , it is already in its most compact form, so simply return element .
  2. If element is an array , :
    1. Initialize a new result to an empty array result . .
    2. Process For each item in element recursively :
      1. Initialize compacted item to the result of using this algorithm, algorithm recursively, passing a copy of the active context , inverse context , and the active property . Add each , and em>item for element .
      2. If compacted item to result unless it is not null . , then append it to result .
    3. If result contains only one item (it has a single item length of 1 ), active property has no container mapping in active context , and the compactArrays option is true , set result to true , return that item; otherwise return its only item.
    4. Return result . .
  3. If Otherwise element is not a JSON object it is already in compact form, return it as is. .
  4. If element has an @value or @id member, replace element with member and the result of using the Value Compaction algorithm . If the updated , passing active context , inverse context , active property ,and element as value is a scalar , return it as it cannot be further compacted. that result.
  5. Initialize a new inside reverse to true if active property equals @reverse , otherwise to false .
  6. Initialize result to an empty JSON object result. .
  7. Process For each key expanded property and value expanded value in element , ordered lexicographically by expanded property as follows: :
    1. If expanded property is a JSON-LD keyword and property equals @id , compact or @type :
      1. If expanded value according is a string , then initialize compacted value to the rules result of using the IRI Compaction algorithm . Otherwise, , passing active context , inverse context , expanded value for iri , and true for vocab if expanded property equals is @type , compact false otherwise.
      2. Otherwise, expanded value (or each item of must be a @type array :
        1. Initialize compacted value if it is to an empty array ) according .
        2. For each item expanded type in expanded value , append the rules result of of using the IRI Compaction algorithm , passing active context , inverse context , expanded type for iri , and true with the vocabRelative flag set for vocab , to true . compacted value .
        3. If compacted value is an array consisting of just contains only one item, replace item (it has a length of 1 ), then set compacted value with that to its only item.
      3. Otherwise, if Initialize alias to the result of using the IRI Compaction algorithm , passing active context , inverse context , and expanded property equals for iri .
      4. Add a member alias to result whose value is set to compacted value and continue to the next expanded property .
    2. If expanded property is @graph , compact @reverse :
      1. Initialize compacted value by recursively invoking to the result of using this algorithm, algorithm recursively, passing a copy of the active context , inverse context , @reverse for active property , and expanded value for element .
      2. For each property as active and value in compacted value :
        1. If the term definition for property in the active context ensuring indicates that property is a reverse property
          1. If compactArrays is false and value is not an array , set value to a new array containing only value .
          2. If property is not a member of result , add one and set its value to value .
          3. Otherwise, if the value of the property member of result is not an array . , set it to a new array containing only the value. Then append value to its value if value is not an array , otherwise append each of its items.
          4. Set active Remove the property member from compacted value .
      3. If compacted value has some remaining members, i.e., it is not an empty JSON object :
        1. Initialize alias to the result of performing using the IRI Compaction on property . algorithm , passing active context , inverse context , and @reverse for iri .
        2. Set the active property value of the alias member of result to compacted value . Continue and continue with the next expanded property - value pair from element . .
    3. If value expanded property is an empty array , set @index and active property has a container mapping in active context that is @index , then the compacted result will be inside of an @index container, drop the @index property by continuing to the next expanded property .
    4. Otherwise, if expanded property is @index , @value , or @language :
      1. Initialize alias to the result of performing using the IRI Compaction on algorithm , passing active context , inverse context , and expanded property with the vocabRelative flag for iri .
      2. Add a member alias to result whose value is set to true . expanded value and continue with the next expanded property .
    5. If active property is a JSON object , i.e., it expanded value is a property generator , set an empty array :
      1. Initialize item active property to the result of performing using the Find and Remove Property Generator Duplicates IRI Compaction algorithm , passing element , property , null for value, the active context , and active inverse context , expanded property . for iri , expanded value for value , true for vocab , and inside reverse .
      2. Ensure that If result has an does not have the key that equals item active property member; if not create it and , set its this key's value in result to an empty array . Continue with Otherwise, if the next property - key's value pair from element . is not an array , then set it to one containing only the value.
    6. Otherwise perform At this point, expanded value must be an array due to the following steps for Expansion algorithm . For each item of expanded item in expanded value : :
      1. Set Initialize item active property to the result of performing using the IRI Compaction algorithm , passing active context , inverse context , expanded property for iri , expanded item for value , true on for vocab , and inside reverse .
      2. Initialize container to null . If there is a container mapping for item active property with the vocabRelative flag in active context , set container to true . its value.
      3. If Initialize compacted item to the result of using this algorithm recursively, passing active context , inverse context , item active property for active property , expanded item for element if it does not contain the key @list , otherwise pass the key's associated value for element .
      4. If expanded item is a JSON list object :
        1. If compacted item is not an array , i.e., then set it to an array containing only compacted item .
        2. If container is not @list :
          1. Convert compacted item to a property generator , set active property list object by setting it to a JSON object containing key-value pair where the key is the result of performing the Find and Remove Property Generator Duplicates IRI Compaction algorithm , passing element , property , item , the active context , inverse context , @list for iri , and active property . compacted item for value .
          2. If expanded item contains the key @index , then add a key-value pair to compacted item where the key is the result of the IRI Compaction algorithm , passing active property's context , inverse context , @index as iri , and the associated with the @index key in expanded item as value .
        3. Otherwise, item active property must not be a key in result because there cannot be two list objects associated with an active property that has a container mapping is set ; a compaction to list of lists error has been detected and processing is aborted.
      5. If container is @language or @annotation @index :
        1. Unless result has already an If item active property member, create one and is a key in result , then initialize map object to its value associated value, otherwise initialize it to an empty JSON object . This object
        2. If container is called mapObject . @language and compacted item contains the key @value , then set compacted item to the value associated with its @value key.
        3. Set index Initialize map key to the value of associated with with the key that equals container in expanded item .
        4. If map key is not a key in map object , then set this key's value in map object to compacted item . Otherwise, if the value is not an array , then set it to one containing only the value and then append compacted item to it.
      6. Otherwise,
        1. If compactArrays is false , container is @language @set or @annotation @list , or expanded property is @list member of or @graph and compacted item (depending on is not an array , set it to a new array containing only compacted item .
        2. If item active property is not a key in result then add the key-value pair, ( item active property - compacted item ), to result .
        3. Otherwise, if the value of associated with the key that equals item active property's container mapping property in result is not an array , set it to a new array ). containing only the value. Then append compacted item to the value if compacted item is not an array , otherwise, concatenate it.
  8. First compact item using Return result .

If, after the Value Compaction algorithm passing index as containerValue , then compact outlined above is run, the result result is an array , replace it by recursively invoking this algorithm passing with a copy new JSON object with a single member whose key is the result of using the IRI Compaction algorithm , passing active context , inverse context , and @graph as iri and whose value is the active property . If no index array result . Finally, if a context has been passed, add an @context member exists in the mapObject create one to result and set its value to item ; otherwise append item to the index member (converting passed context .

8.2 Inverse Context Creation

When there is more than one term that could be chosen to compact an IRI , it has to be ensured that the term selection is both deterministic and represents the most context-appropriate choice whilst taking into consideration algorithmic complexity.

In order to make term selections, the concept of an array inverse context is introduced. An inverse context is essentially a reverse lookup table that maps container mappings , type mappings , and language mappings to a simple term for a given active context . A inverse context only needs to be generated for an active context if it is not one already). Continue with being used for compaction .

To make use of an inverse context , a list of preferred container mappings and the next property - type mapping or language mapping are gathered for a particular value pair from element . If associated with an IRI . These parameters are then fed to the Term Selection algorithm , which will find the term that most appropriately matches the value's mappings.

General Solution

item This section is a JSON object non-normative.

To create an inverse context having for a @list member, compact given active context , each term in the value active context is visited, ordered by length, shortest first (ties are broken by choosing the lexicographically least term ). For each term , an entry is added to the inverse context for each possible combination of container mapping and type mapping or language mapping that member by recursively invoking this algorithm passing would legally match the term . Illegal matches include differences between a copy value's type mapping or language mapping and that of the active context term . If a term has no container mapping , type mapping , or language mapping (or some combination of these), then it will have an entry in the inverse context , using the special key @none . This allows the Term Selection algorithm to fall back to choosing more generic terms when a more specifically-matching term is not available for a particular IRI and value combination.

Algorithm

The algorithm takes one required input: the active property context ensuring that the result inverse context is being created for.

  1. Initialize result to an array empty JSON object .
  2. Initialize default language to @none . If the active property's container mapping context is has a default language , set default language to @list , set it.
  3. For each key term and value term definition in the active property context , ordered by shortest term member of result to first (breaking ties by choosing the value of item's @list member. lexicographically least term ):
    1. If such an member already exists in result, raise an COMPACTION_TO_LIST_OF_LISTS error; otherwise the term definition is null , term cannot be selected during compaction , so continue with to the next property - value pair from element . term .
    2. Initialize container to @none . If item there is a JSON object container mapping in term definition , compact it by recursively invoking this algorithm passing a copy set container to its associated value.
    3. Initialize iri to the value of the active context , inverse context , and IRI mapping for the active property term definition .
    4. If no active property iri is not a key in result , add a key-value pair where the key is iri and the value is an empty JSON object to result .
    5. Reference the value associated with the iri member exists in result using the variable container map .
    6. If container has no container map member, create one and set its value to item ; otherwise append item to the active property a new JSON object with two members. The first member (converting it to an array if it is not one already). @language and its value is a new empty JSON object , the second member is @type and its value is a new empty JSON object .
    7. Reference the value associated with the container member in container map using the variable type/language map .
    8. If the compactArrays term definition indicates that the term represents a reverse property :
      1. Reference the value associated with the @type option is member in type/language map using the variable type map .
      2. If type map does not have a @reverse member, create one and set its value to the term being processed.
    9. Otherwise, if term definition has a type mapping :
      1. Reference the value associated with the false @type or member in type/language map using the active property's container variable type map .
      2. If type map does not have a member corresponding to the type mapping is in term definition , create one and set its value to the term being processed.
    10. Otherwise, if term definition has a language mapping (might be null ):
      1. Reference the value associated with the @list @language or @set , convert member in type/language map using the value of variable language map .
      2. If the active property language mapping member of result equals null , set language to an array if @null ; otherwise set it is to the language code in language mapping .
      3. If language map does not have a language member, create one already. and set its value to the term being processed.
    11. If, after the algorithm outlined above is run,
    12. Otherwise:
      1. Reference the resulting element is an array replace it value associated with the @language member in type/language map using the variable language map .
      2. If language map does not have a new JSON object default language member, create one and set its value to the term with being processed.
      3. If language map does not have a single member whose name is @none member, create one and set its value to the result of compacting term being processed.
      4. Reference the value associated with the @graph @type with member in type/language map using the IRI Compaction algorithm and whose value is element . Finally, add variable type map .
      5. If type map does not have a @context @none property to element member, create one and set it its value to the initially passed context . term being processed.
  4. Return result .

5.9 8.3 IRI Compaction Algorithm

This section defines an algorithm for transforming compacts an IRI to a term or compact IRI . If , or a keyword to a keyword alias . A value that is associated with the IRI may be passed in order to assist in selecting the most context-appropriate term .

General Solution

This section is non-normative.

If the passed IRI is null , we simply return null . Otherwise, we first try to find a term that the IRI or keyword can be compacted to if it is relative to active context's vocabulary mapping . In order to select the most appropriate term , we may have to collect information about the passed value . This information includes whic container mappings would be preferred for expressing the value , and what its type mapping or language mapping is. For JSON-LD lists , the type mapping or language mapping will be chosen based on the most specific values that work for all items in the list. Once this information is gathered, it is used passed to choose the best matching Term Selection algorithm , which will return the most appropriate term to use.

If no term was found that could be used to compact the IRI , then an attempt is made to find a compact IRI to use. If there is no appropriate compact IRI , then, if the IRI is relative to active context's vocabulary mapping , then it is used. Otherwise, it is transformed to a relative IRI using the document's base IRI . Finally, if the IRI or keyword still could not be compacted, it is returned as is.

Algorithm

This algorithm takes three mandatory required inputs and two three optional parameters. inputs. The mandatory parameters are the iri to be compacted, required inputs an active context , and an inverse context . Optionally it is possible , and the iri to pass be compacted. The optional inputs are a value and associated with the iri , a vocabRelative vocab flag which specifies whether the passed iri should be compacted using the active context's vocabulary mapping . If the vocabRelative , and a reverse flag which specifies whether a reverse property is being compacted. If not passed, value is set to null and vocab and reverse are both set it defaults to false .

The algorithm for generating a compact IRI is:
  1. Initialize a variable result to If iri is null , return null .
  2. If an entry for vocab is true and iri exists is a key in the inverse context , perform the following steps: :
    1. If a value Initialize default language to active context's default language , if it has been passed, perform the following steps: one, otherwise to @none .
    2. Initialize queryPath , which containers to an empty array . This array will be used to query the inverse context , to keep track of an empty array ordered list of preferred container mappings for a term , based on what is compatible with value .
    3. Initialize container type/language to @set @language , typeOrLanguage , and typeLanguageValue type/language value to null . @null . These two variables will keep track of the preferred type mapping or language mapping for a term , based on what is compatible with value .
    4. If value is a JSON object and it has an that contains the key @annotation @index , then append the value @index member, set container to @annotation . containers .
    5. If value has an @id member, reverse is true , set typeOrLanguage type/language to @type and typeLanguageValue , type/language value to @id . @reverse , and append @set to containers .
    6. Otherwise, if value has an @value member, is a list object , then set type/language and type/language value to the most specific values that work for all items in the list as follows:
      1. and an If @type @index member, set typeOrLanguage to is a not key in value , then append @type @list and typeLanguageValue to containers .
      2. Initialize list to the value of array associated with the key @type @list member of in value . .
      3. Otherwise, if it has an @language member, Initialize common language to null . If list is empty, set typeOrLanguage common language to default language .
      4. For each item in list :
        1. Initialize item language to @language @none and typeLanguageValue item type to @none .
        2. If item contains the value of the key @language member of value . @value :
          1. If value has no item contains the key @annotation member, @language , then set container item language to @language its associated value.
          2. Otherwise, if item contains the value of value's key @value member is is a string , @type , set typeOrLanguage item type to @language and typeLanguageValue its associated value.
          3. Otherwise, set item language to @null .
        3. Otherwise, if value has an set item type to @list member, @id .
        4. If the @list member has at least one item, update container , typeOrLanguage , and typeLanguageValue by recursively running the steps 2.1.2 common language is null , set it to 2.1.3.4 (which will never be true since list of lists are item language .
        5. Otherwise, if item language does not allowed) of this algorithm passing the first equal common language and item of value's contains the key @list @value , then set common language to @none member as new value . because list items have conflicting languages.
        6. If value has no @annotation member, common type is null , set container it to @list . item type .
        7. Starting from the second Otherwise, if item of value's type does not equal common type , then set common type to @list @none member, recursively run the steps 2.1.2 to 2.1.3.4 (which will never be true since because list of lists are not allowed) of this algorithm passing the item as new value . items have conflicting types.
        8. If common language is @none and common type is @none , then stop processing items in the resulting typeOrLanguage list because it has been detected that there is no common language or typeLanguageValue differ from type amongst the current value of typeOrLanguage or typeLanguageValue , items.
      5. If common language is null , set both it to @none .
      6. If common type is null and stop processing the , set it to @list @none .
      7. If common type is not @none items. then set type/language to @type and type/language value to common type .
      8. Otherwise, set type/language value to common language .
    7. Otherwise:
      1. If value is a value object :
        1. If value contains the container equals key @list @language and does not contain the key @index , then set the first item of queryPath type/language value to an array consisting of the two elements @list its associated value and append null @language ; otherwise set it to an array consisting of three elements where the first element is the containers .
        2. Otherwise, if value of container and contains the other two elements are key @set @type , then set type/language value to its associated value and set type/language to @null @type .
      2. If typeOrLanguage is null , Otherwise, set the second type/language to @type and the the third item of queryPath set type/language value to an array consisting of a single element @null @id .
      3. Otherwise, set the second item of queryPath Append @set to an array consisting containers .
    8. Append @none to containers . This represents the non-existence of two elements where a container mapping , and it will be the first element last container mapping value to be checked as it is the most generic.
    9. If type/language value of typeOrLanguage and the second element is null , set it to @null . Set This is the third item of queryPath key under which null values are stored in the inverse context entry .
    10. Initialize preferred values to an empty array . This array whose first element typeLanguageValue and whose second element will indicate, in order, the preferred values for a term's type mapping or language mapping .
    11. If type/language value is @null . @reverse , append @reverse to preferred values .
    12. Query If type/language value is @id or @reverse and value has an @id member:
      1. If the result of using the IRI compaction algorithm , passing active context , inverse context and store , the result value associated with the @id key in result . If result is a a string value for iri , true or for vocab , and true for document relative has a JSON object term definition in the active context with a an IRI mapping that equals the value associated with the term @id member, return result . key in value , then append @vocab , @id , and @none , in that order, to preferred values .
      2. Otherwise, append @id , @vocab , and @none , in that order, to preferred values .
    13. Otherwise, if the entry for iri append type/language value and @none , in that order, to preferred values .
    14. Initialize term to the result of the Term Selection algorithm , passing inverse context has a , iri , containers , type/language , and preferred values .
    15. If term member, is not null , return its value. term .
  3. At this point, there is no simple term that iri can be compacted to. Instead, try to create a compact IRI , starting by initializing compact IRI to null . This variable will be used to store the created compact IRI , if any.
  4. For each termIri - termDefinition pair in inverse context key term and value term definition sorted in reverse order by termIri the (longest termIri comes first), perform the following steps: active context :
    1. If termDefinition does not have a the term member, i.e., it is contains a property generator, colon ( : ), then continue with to the next termIri - termDefinition pair from inverse context term because terms with colons can't be used as prefixes .
    2. Otherwise, if iri begins with termIri and If the term definition is longer than termIri , generate a compact null , its IRI mapping equals iri , or its IRI mapping by concatenating is not a substring at the value beginning of iri , the term member of termDefinition cannot be used as a prefix because it is not a partial match with iri . Continue with the next term .
    3. Initialize candidate by concatenating term , a colon ( : ) character ), and the unmatched part substring of iri . that follows after the value of the term definition's IRI mapping .
    4. If either compact IRI is null or candidate is shorter or the resulting same length but lexicographically less than compact IRI and candidate does not have a term definition has an entry in the active context , continue with the next termIri - termDefinition pair from inverse context as or if the term definition has an IRI mapping that equals iri and value is null , set compact IRI cannot be used. to candidate .
  5. Otherwise, if result If compact IRI is not null , return the compact IRI ; if it .
  6. At this point, there is not null, set the term member of result to the no compact IRI and return result . If the vocabRelative flag that iri can be compacted to, so if vocab is set to true , the and active context has a vocabulary mapping , and :
    1. If iri begins with the IRI of the vocabulary mapping mapping's value but is longer Set vocabIri longer, then initialize suffix to the unmatched part substring of iri . that does not match. If there suffix does not exist an entry for vocabIri have a term definition in the active context , then return vocabIri if result is null ; if it is not null set the term member of result to vocabIri and return result . suffix .
  7. If result vocab is null , return false then transform iri as is. to a relative IRI using the document's base IRI .
  8. Otherwise set the term member of result to iri and Finally, return result . iri as is.

5.10 8.4 Inverse Context Creation Term Selection

An active context as produced by the Context Processing algorithm is very efficient for expanding terms and compact IRIs to IRIs but is of limited use for This algorithm, invoked via the opposite operation: IRI compaction . Hence, this Compaction algorithm introduces the notion , makes use of an active context's inverse context which brings to find the same efficiency term that is best used to compact an IRI compaction . An inverse context a tree of JSON objects which allow to efficiently select a term for Other information about a value associated with the IRI -value pair. The value takes an active context is given, including which container mappings and returns which type mapping or language mapping would be best used to express the corresponding inverse context . value.

Set

General Solution

defaultLanguage This section is non-normative. to active

The inverse context's default language if there is one; otherwise set it to @null . For each term definition in the active context perform the following steps: If entry for the term's IRI mapping is set will be first searched according to null continue with the next term definition . Set preferred container to the value of mappings , in the term's order that they are given. Amongst terms with a matching container mapping , preference will be given to those with a matching type mapping or @null if no such language mapping exists. , over those without a type mapping or language mapping . If the there is no term is with a property generator , set termType to propertyGenerators . Otherwise set set termType to term and append the term matching container mapping to then the term member of the JSON object for without a container mapping that matches the term's given type mapping IRI in inverse context or language mapping (append term to inverseContext[iri]['term'] ). For each iri mapped to the is selected. If there is still no selected term , perform the following steps: If the then a term has a with no type mapping to type , append the term or language mapping to inverseContext[iri][container]['@type'][type][termType] , e.g., inverseContext['http://...']['@list']['@type']['http://...']['term'] . Otherwise, will be selected if the available. No term will be selected that has a language conflicting type mapping store the associated language in language , replacing null with @null . Then append the term to inverseContext[iri][container]['@language'][language][termType] , e.g., inverseContext['http://...']['@list']['@language']['de']['term'] . Otherwise append the term to inverseContext[iri][container]['@null']['@null'][termType] as well as inverseContext[iri][container]['@language'][defaultLanguage][termType] to take the default language into consideration for terms without explicit or language mapping . Remove all but Ties between terms that have the same mappings are resolved by first choosing the shortest terms, and lexicographically least term in each term member in inverse context . The result is thus a single string value. Finally, sort then by choosing the array associated with every propertyGenerators member in inverse context lexicographically (shortest terms come first). 5.11 Inverse Context Query Algorithm It is possible that multiple terms least term. Note that differ in their container , type , or language mapping these ties are mapped to resolved automatically because they were previously resolved when the same IRI . The purpose of this Inverse Context Creation algorithm is was used to query create the inverse context to return either the best matching term , or a list of potential property generators along with a term to fall back to if none of the property generators can be applied. .

Algorithm

This algorithm takes has five required inputs. They are: an inverseContextSubtree , inverse context , a queryPath as generated by the keyword or IRI Compaction algorithm and a level parameter which is initialized to 0 if nothing else is passed. The algorithm returns either iri , an array containers that represents an ordered list of preferred container mappings , a string representing the best matching term or type/language that indicates whether to look for a JSON object term consisting of a propertyGenerators member, containing with a sorted array matching type mapping of potential property generators or language mapping , and an optional term member containing a term array to fall back to if none representing an ordered list of preferred values for the property generators type mapping can be applied. or language mapping to look for.

  1. Initialize result container map to null . If level equals 3 , i.e., the deepest nested JSON object value associated with iri in the inverse context has been reached, perform the following steps: .
  2. If inverseContextSubtree has a propertyGenerators member, copy that member into a new JSON object and store that object For each item container in result . containers :
    1. If inverseContextSubtree has a term member and result container is null , return the value of that member; otherwise result not a key in container map , then there is no term with a JSON object , copy matching container mapping for it, so continue to the term member into result and return result . next container .
    2. Otherwise, for each entry of the array in queryPath's level'd position ( queryPath[level] ), perform Initialize type/language map to the following steps: If inverseContextSubtree has no entry member, continue value associated with the next entry . container member in container map .
    3. Otherwise set tmpResult Initialize value map to the result of recursively invoking this algorithm passing the entry value associated with type/language member of inverseContextSubtree as new inverseContextSubtree , queryPath , and level + 1 as new level . in type/language map .
    4. For each item in preferred values :
      1. If tmpResult is a string and result is null , return tmpResult ; otherwise, if result item is not null , transform tmpResult to a JSON object whose propertyGenerators member key in value map , then there is set to an empty array and whose no term member is set to tmpResult . If result is null , replace it with tmpResult . a matching type mapping or language mapping , so continue to the next item .
      2. Otherwise, append each item of a matching term has been found, return the propertyGenerator member of tmpResult to value associated with the propertyGenerator item member of result unless it is already in result's member. If result has no term member but tmpResult does, copy tmpResult's term member into result . value map .
  3. No matching term has been found. Return result . null .

5.12 8.5 Value Compaction

Expansion transforms all values into expanded form in JSON-LD. This algorithm does the opposite, it compacts an algorithm according the term definition of the passed active property . After performs the application of this algorithm opposite operation, transforming a value is said to be in into compacted form . This algorithm takes compacts a value , an according to the term definition in the given active context , an inverse context , an that is associated with the value's associated active property , and an optional containerValue . .

If a

General Solution

containerValue This section is non-normative.

The value to compact has been passed, either an @id or an @value member.

For the former case, if the type mapping of active property has a container mapping is set to @annotation @id or @vocab and value has consists of only of an @annotation @id member which equals containerValue , remove that member. If value is a JSON object and, if if the container mapping having a single member of active property is set to @id @index , return an @index member, value can be compacted to a string by returning the result of performing using the IRI Compaction algorithm on that member's value. to compact the value associated with the @id member. Otherwise, if value cannot be compacted and is a JSON object having a returned as is.

For the latter case, it might be possible to compact value just into the value associated with the @value member, perform the following steps: If member. This can be done if the active property has a matching type mapping or language mapping and value has a corresponding there is either no @type @index member, remove member or the container mapping of active property is set to @type @index . It can also be done if @value is the only member from in value . Otherwise, if (apart an @index member in case the container mapping of active property has is set to @index ) and either its associated value is not a string , there is no default language , or there is an explicit null language mapping for the active property .

Algorithm

This algorithm has four required inputs: an active context , an inverse context , an active property , and a value to be compacted.

  1. Initialize number members to the number of members value contains.
  2. If value has a corresponding an @language @index member, remove member and the container mapping associated to active property is set to @language member from @index , decrease number members by 1 .
  3. If number members is greater than 2 , return value . as it cannot be compacted.
  4. Otherwise, if a containerValue If value has been passed, an @id member:
    1. If number members is 1 and the type mapping of active property has a container mapping is set to @language @id , return the result of using the IRI compaction algorithm , passing active context , inverse context , and the value has a @language member which equals containerValue , remove of the @language @id member from value . for iri .
    2. Otherwise, if number members is 1 and the type mapping of active property is set to @vocab , return the result of using the IRI compaction algorithm , passing active context , inverse context , the value of the @id member for iri , and true for vocab .
    3. Otherwise, return value as is.
  5. Otherwise, if value has a default language an @type member whose value matches the type mapping and of active property , return the value associated with the @value member of value .
  6. Otherwise, if value has a corresponding an @language member, remove member whose value matches the language mapping of active property , return the value associated with the @language @value member from of value . .
  7. Otherwise, or if number members equals 1 and either the value of value's the @value member is not a string , or the active context has no default language , or the language mapping of active property is set to null ,, return value . If the value has just a associated with the @value member, return the value of that member.
  8. Return Otherwise, return value as is.

9. Flattening Algorithms

5.13 9.1 Find and Remove Property Generator Duplicates Flattening Algorithm

This algorithm checks if a specific value exists for flattens an expanded JSON-LD document by collecting all IRIs properties of a node associated with in a property generator single JSON object and if so, it removes them. The algorithm takes five parameters: element , property , value , active context , active property . For each item propertyGenerator of the array labeling all blank nodes which is the value with blank node identifiers . This resulting uniform shape of the propertyGenerators member of active property perform document, may drastically simplify the following steps: Check that a member exists for each code required to process JSON-LD data in certain applications.

General Solution

IRI

associated with the propertyGenerator . If value This section is non-normative.

First, a node map is not null also check whether each of those members that contains value . Values are considered to be equal if they are of the same type and have generated using the same value(s); node objects Node Map Generation algorithm are considered to be equal if which collects all members match, except if no @id member exists (i.e., it is an unlabeled blank node , in that case properties of a node objects are never considered to be equal. If that's not the case, continue with in a single JSON object . In the next propertyGenerator . Otherwise, remove value from every member. If step, the resulting value of a member node map is an empty array , remove the member altogether from element . Return propertyGenerator . Return the value of the term member of active property since no matching property generator converted to a JSON-LD document in flattened document form . Finally, if a context has been found. passed, the flattened document is compacted using the Compaction algorithm before being returned.

5.14 Flattening

Algorithm

The algorithm takes two input variables, an element to flatten and a an optional context used to compact the flattened document. If not passed, context is set to null .

  1. Expand element according the Expansion algorithm Initialize node map to a JSON object consisting of a single member whose key is @default and whose value is an empty JSON object .
  2. Generate a nodeMap according Perform the Node Map Generation algorithm . , passing element and node map .
  3. Let defaultGraph be Initialize default graph to the value of the @default member of nodeMap ; node map , which is a JSON object representing the default graph .
  4. For each other graphName key-value pair graph name - graph pair in nodeMap node map where graph name is not @default , perform the following steps:
    1. If defaultGraph default graph does not have a graphName graph name member, create one and initialize its value to a JSON object consisting of an @id member whose value is set to graphName . graph name .
    2. Reference the value associated with the graph name member in default graph using the variable entry .
    3. Add a an @graph member to entry and set it to an empty array (referred to as nodes ) to the JSON object which is the value of the graphName member of nodeMap . .
    4. For each id - node pair in graph ordered by id , , add node to the nodes array . @graph member of entry .
  5. Initialize an empty array flattened. flattened .
  6. For each id - node pair in defaultGraph default graph ordered by id , , add node to flattened . .
  7. If context equals is null , return flattened . .
  8. Otherwise, return the result of compacting flattened according the Compaction algorithm passing context ensuring that the compaction result uses the @graph keyword (or its alias) at the top-level, even if the context is empty or if there is only one element to put in the @graph array . This ensures that the returned document has a deterministic structure.

5.15 9.2 Node Map Generation

This algorithm creates a JSON object nodeMap node map holding an indexed representation of the graphs and nodes represented in the passed, passed expanded document. All nodes that are not uniquely identified by an IRI get assigned a (new) blank node identifier . The resulting nodeMap node map will have a member for every graph in the document whose value is another object with a member for every node represented in the document. The default graph is stored under the @default member, all other graphs are stored under their graph name. name .

General Solution

This section is non-normative.

The algorithm recursively runs over an expanded JSON-LD document to collect all properties of a node in a single JSON object . The algorithm constructs a JSON object node map whose keys represent the graph names used in the document (the default graph is stored under the key @default ) and whose associated values are JSON objects which index the nodes in the graph . If a property's value is a node object , it is replace by a node object consisting of only an @id member. If a node object has no @id member or it is identified by a blank node identifier , a new blank node identifier is generated. This relabeling of blank node identifiers is also be done for properties and values of @type .

Algorithm

The algorithm takes as input an expanded JSON-LD document element and a reference to a JSON object nodeMap . node map . Furthermore it has the optional parameters active graph (which defaults to @default ), an active subject , active property , and a reference to a JSON object list . The nodeMap must be initialized to a JSON object consisting of a single member whose name corresponds with . If not passed, active graph subject , active property , and whose value is an empty JSON object list are set to null .

  1. If element is an array, process each entry item in element recursively, using as follows and then return:
    1. Run this algorithm recursively by passing item for element , node map , active graph , active subject , active property , and return. list .
  2. Otherwise element is a JSON object . Let activeGraph be Reference the JSON object which is the value of the active graph member of nodeMap . node map using the variable graph . If the active subject is null , set node to null otherwise reference the active subject member of graph using the variable node .
  3. If it element has a an @type member, perform for each item the following steps:
    1. If item is a blank node identifier , replace it with a newly new generated blank node identifier . passing item for identifier .
    2. If activeGraph graph has no member item , , create it one and initialize its value to a JSON object consisting of a single member @id with the whose value is item . .
  4. If element has an @value member, perform the following steps:
    1. If active property list is null , generate a blank node identifier id and store element as value of the member id in activeGraph . Issue 207 Handling of free-floating values is still being discussed. Otherwise, if no list has been passed, merge element into the active property member of node ; the active subject resulting array in activeGraph . must not contain any duplicate values.
    2. Otherwise, append element to the @list member of list . .
  5. Otherwise, if element has an @list member, perform the following steps:
    1. Initialize a new JSON object result having consisting of a single member @list whose value is initialized to an empty array .
    2. Recursively call this algorithm passing the value of element's @list member as new for element and result as list . If , active graph , active subject , active property is null , generate a blank node identifier id and store result as value of the member id in activeGraph . Issue 207 Handling of free-floating values is still being discussed. for list .
    3. Otherwise, add Append result to the the value of the active property member of the active subject in activeGraph . node .
  6. Otherwise element is a node object , perform the following steps:
    1. If element has an @id member, store set id to its value in id and remove the member from element . . If id is a blank node identifier , replace it with a new newly generated blank node identifier . passing id for identifier .
    2. Otherwise Otherwise, set id to the result of the generate a new blank node identifier Generate Blank Node Identifier algorithm and store it as id . passing null for identifier .
    3. If activeGraph graph does not contain a member id , , create one and initialize it its value to a JSON object consisting of a single member @id whose value is set to id . .
    4. If active property is not null , perform the following steps:
      1. Create a new JSON object reference consisting of a single member @id whose value is id . .
      2. If no list has been passed, is null , merge element into the active property member of node ; the active subject resulting array in activeGraph . must not contain any duplicate values.
      3. Otherwise, append element to the @list member of list . .
    5. Reference the value of the id member of graph using the variable node .
    6. If element has an @type member, merge each value of its values into the @type member of active subject in activeGraph . Then node and finally remove the @type member from element . ; the resulting array must not contain any duplicate values.
    7. If element has an @annotation @index member, set the @annotation @index member of active subject in activeGraph node to its value. If such a member already exists in active subject node and has already an @index member with a different value, raise a CONFLICTING_ANNOTATION conflicting indexes error. Otherwise error has been detected and processing is aborted. Otherwise, continue by removing the @index member from element .
    8. If element has an @reverse member:
      1. Create a JSON object referenced node with a single member @id whose value is id .
      2. Set reverse map to the value of the @reverse member of element .
      3. For each key-value pair property - values in reverse map :
        1. For each value of values :
          1. If value has a property member, append referenced node to its value; otherwise create a property member whose value is an array containing referenced node .
          2. Recursively invoke this algorithm passing value for element , node map , and remove active graph .
      4. Remove the @annotation @reverse member from element . .
    9. If element has an @graph member, recursively invoke this algorithm passing the value of the @graph member as new for element , node map , and id as new for active subject . Then remove graph before removing the @graph member from element . .
    10. Finally Finally, for each key-value pair property - value pair in element ordered by property perform the following steps:
      1. If no property member exists in the JSON object which is the value of the id member of activeGraph a blank node identifier , replace it with a newly generated blank node identifier passing property for identifier .
      2. If node does not have a property member, create the member one and initialize its value to an empty array .
      3. Recursively invoke this algorithm passing value as new for element , , node map , active graph , id as new for active subject , and property as new for active property . , and list .

5.16 9.3 RDF Conversion Algorithms Generate Blank Node Identifier

This specification describes algorithms algorithm is used to transform JSON-LD documents generate new blank node identifiers or to relabel an array of RDF quads existing blank node identifier and vice-versa. Note that many uses of JSON-LD may not require generation to avoid collision by the introduction of RDF. new ones.

General Solution

This section is non-normative.

The processing algorithms described simplest case is if there exists already a blank node identifier in this section are provided the identifier map for the passed identifier , in order to demonstrate how which case it is simply returned. Otherwise, a new blank node identifier is generated by concatenating the string _:b and the counter . If the passed identifier is not null , an entry is created in the identifier map associating the identifier with the blank node identifier . Finally, the counter is increased by one might implement and the new blank node identifier is returned.

Algorithm

The algorithm takes a JSON-LD single input variable identifier which may be null . Between its executions, the algorithm needs to RDF processor. Conformant implementations are only required keep an identifier map to produce the same type relabel existing blank node identifiers consistently and number of quads a counter to generate new blank node identifiers . The counter is initialized to 0 by default.

  1. If identifier is not null but are and has an entry in the identifier map , return the mapped identifier.
  2. Otherwise, generate a new blank node identifier by concatenating the string _:b and counter .
  3. Increment counter by 1 .
  4. If identifier is not required null , create a new entry for identifier in identifier map and set its value to implement the algorithm exactly as described. Issue This algorithm hasn't been updated yet. new blank node identifier .
  5. Return the new blank node identifier .

5.16.1 10. Convert to RDF Algorithm Conversion Algorithms

This section describes algorithms to transform a JSON-LD document to an RDF dataset and vice versa. The algorithm below is algorithms are designed for in-memory implementations with random access to JSON object elements.

A conforming JSON-LD processor implementing RDF conversion must implement a processing algorithm that results in the same set of RDF quads that Throughout this section, the following algorithm generates: vocabulary prefixes are used in compact IRIs :

Prefix IRI
rdf http://www.w3.org/1999/02/22-rdf-syntax-ns#
rdfs http://www.w3.org/2000/01/rdf-schema#
xsd http://www.w3.org/2001/XMLSchema#

10.1 Convert to RDF Algorithm

The algorithm takes four input variables: This algorithms converts a element JSON-LD document to be converted, an active subject , active property and graph name RDF dataset . To begin, the active subject , active property

Issue 217 and graph name

RDF does not currently allow a blank node identifier are set to null , and be used as a graph name .

General Solution

element This section is non-normative.

The JSON-LD document is set expanded and converted to a node map using the result of performing Node Map Generation algorithm . This allows each graph represented within the Expansion Algorithm on document to be extracted and flattened, making it easier to process each node object . Each graph from the JSON-LD input node map is processed to extract RDF triples , to which any (non-default) graph name is expected applied to be a a well-formed JSON-LD document as defined create an RDF dataset . Each node object in [ the node map has an @id member which corresponds to the RDF subject , the other members represent RDF predicates . Each member value is either an JSON-LD IRI ]. This removes any existing context or blank node identifier or can be transformed to allow an RDF literal to generate an RDF triple . Lists are transformed into an RDF Collection using the given context List to be cleanly applied. RDF Conversion algorithm.

Algorithm

The algorithm takes a JSON-LD document element and returns an RDF dataset .

    If
  1. Expand element is according the Expansion algorithm .
  2. Generate a JSON object , perform node map according the following steps: Node Map Generation algorithm .
  3. Set active object Initialize an empty RDF dataset to null dataset .
  4. For each graph name and graph in node map :
    1. Initialize triples as an empty array .
    2. If element has a @value property: For each subject and node in graph :
      1. For each property and values in node :
        1. If the value of @value property is @type , then for each type in values , append a number , set the active object triple composed of subject , rdf:type , and type to triples .
        2. Otherwise, if property is a typed value using a canonical lexical form keyword of the value as defined in the section Data Round Tripping . Set datatype continue to the value of the @type next property if it exists, otherwise either xsd:integer or xsd:double , depending on if the value contains a fractional and/or an exponential component. - values pair.
        3. Otherwise, if the value of @value property is true an IRI or false , set the active blank node identifier . For each item in values :
          1. If item is a list object , initialize list triples as an empty array and list head to a typed value created from the canonical lexical form result of the value. Set datatype to List Conversion algorithm , passing the value of associated with the @type @list property if it exists, otherwise xsd:boolean . Otherwise, if element contains key from item and list triples . Append first a @type property, set the active object triple composed of subject , property , and list head to a typed value . triples and finally append all triples from list triples to triples .
          2. Otherwise, if element contains item is a @language property, set the active value object to or a language-tagged string . Otherwise, set the active node object to . Append a typed value triple composed of subject , property , and the result of using xsd:string as the datatype. Object to RDF Conversion algorithm passing item to triples .
    3. If element has a graph name is @list property the value must be an array . Process its value as a list as described in List Conversion using the return value as @default , add triples to the active object default graph in dataset .
    4. If active object is not null : If neither active subject nor active property are null , generate Otherwise, create a Quad named graph representing active subject , active property , active object , and in dataset composed of graph name . and add triples .
  5. Return active object . dataset .
If element has

10.2 Object to RDF Conversion

This algorithm takes a @id property, the node object or value must be a string , set the active subject object and transforms it into an RDF resource to be used as the previously expanded value (either a blank node object or of an RDF triple .

General Solution

IRI

). Otherwise, if element This section is non-normative. does not have a @id property, set

Value objects are transformed to RDF literals as defined in the active subject section Data Round Tripping whereas node objects are transformed to newly generated IRIs or blank node identifiers . Process each property and value in element , ordered by property ,

Algorithm

The algorithm takes as follows: its sole argument item which must be either a value object or node object .

  1. If property item is @type , set a node object return the active property IRI to or blank node identifier associated with its rdf:type . @id member.
  2. Otherwise, if property item is @graph , process a value algorithm recursively, using active subject as graph name and null values for active subject and active property and then proceed object . Initialize value to next property. Otherwise, if property is a keyword , skip this step. the value associated with the @value member in item .
  3. Otherwise, set active property Initialize datatype to the expanded IRI form value associated with the @type member of property . item or null if item does not have such a member.
  4. Process If value recursively using this algorithm, passing copies of active subject is true or false , active property set value to its canonical lexical form and graph name as defined in the section Data Round Tripping . Set active object If datatype is null , set it to active subject . xsd:boolean .
  5. Otherwise, if element value is an array a number , process each then set value in the array to its canonical lexical form as follows, process element recursively using this algorithm, using copies of active subject , active property , and graph name defined in the section Data Round Tripping . If datatype is null , set it to either xsd:integer or xsd:double , depending on if the value contains a fractional and/or an exponential component.
  6. Otherwise, if element datatype is a string null , then the active property must be rdf:type so set the active object it to xsd:string or rdf:langString , depending on if item has an IRI . @language member.
  7. If any of these steps created Initialize literal as an active object and neither active subject nor active property are null , generate a Quad RDF literal using active subject , active property , active object value and graph name . datatype . If item has an @language member and datatype is rdf:langString , then add the value associated with the @language key as the language of literal .
  8. Return active object . literal .

5.16.2 10.3 List to RDF Conversion

List Conversion is the process of taking an array a list object of values and adding them to a newly created transforming it into an RDF Collection (see as defined in RDF Semantics [ RDF-SCHEMA RDF-MT ]) by linking ].

General Solution

This section is non-normative.

For each element of the list using a new blank node identifier is allocated which is used to generate rdf:first and rdf:next , terminating rdf:rest triples . The algorithm returns the list with head, which is either the the first allocated blank node identifier or rdf:nil using if the following sequence: list is empty.

Algorithm

The algorithm is invoked with takes two inputs: an array array , the active property list and returns a value to be used as an active object empty array in list triples used for returning the calling location. Note This algorithm does not support lists containing lists. Issue This algorithm hasn't been updated yet. generated triples .

  1. If array list is empty empty, return rdf:nil .
  2. Otherwise, generate a Quad using using the active subject , active property create an array and bnodes composed of a newly generated blank node identifier identified as first blank node for each entry in list .
  3. Initialize an empty array . list triples .
  4. For each element in array other than the last element: pair of subject from bnodes and item from list :
    1. Create Append a processor state using first blank node as the active triple composed of subject , and , rdf:first as the active property . Process , and the value starting at Step 1 . Proceed result of using the previous processor state . th Object to RDF Conversion algorithm passing item to list triples .
    2. Unless this is Set rest as the last element next entry in array , generate a new blank node identified as rest blank node , otherwise use bnodes , or if that does not exist, rdf:nil . Generate Append a new Quad triple using first blank node , composed of subject , rdf:rest , and rest blank node . Set first blank node to rest blank node . list triples .
  5. Return the first blank node . from bnodes or rdf:nil if bnodes is empty.

5.16.3 10.4 Convert from RDF Algorithm

This algorithm converts an RDF dataset consisting of a default graph and zero or more named graphs into a JSON-LD document.

In some cases, data exists natively in the form of triples or or quads triples ; for example, if the data was originally represented in an RDF graph or triple/quad store. dataset . This algorithm is designed to simply translate an array of quads triples into a JSON-LD document.

Note

This algorithm does not support lists containing lists.

General Solution

When expanding typed values This section is non-normative.

Iterate through each graph in the dataset, converting RDF Collections having into a datatype of xsd:string , the @type must not be set to xsd:string list and the resulting value must have only generating a @value property. JSON-LD document in expanded form for all RDF literals , IRIs and blank node identifiers .

Algorithm

The conversion algorithm takes a single parameter input dataset in the form of an array of Quad representations. Issue This algorithm hasn't been updated yet. an RDF dataset .

    Construct defaultGraph as
  1. Initialize default graph to a new JSON object containing nodes consisting of two members, nodeMap and listMap , each , whose value is an an empty JSON object .
  2. Construct graphs as a Initialize graph map to an empty JSON object containing defaultGraph identified by an empty string . consisting of a single member @default whose value is set to reference default graph .
  3. Reference the nodeMap member of default graph using the variable default graph nodes .
  4. For each quad graph in input : dataset :
    1. Set If graph is the default graph , set name to @default , otherwise to the entry in graphs identified by graph name , initializing it associated with graph .
    2. If graph map has no name member, create one and set its value to a to a new entry using the mechanism described in Step 1 JSON object consisting of two members, nodeMap and listMap , whose value is an an empty JSON object .
    3. If property graph is rdf:first , use not the entry in graph.listMap indexed by subject , initializing it default graph and default graph nodes does not have a name member, create such a member and initialize its value to a new JSON object if nesessary. Represent object in expanded form , as described with a single member @id whose value is name .
    4. Reference the value of the name member in Value Expansion . Add graph map using the resulting variable graph object representation to .
    5. Reference the entry indexed by first , value of the nodeMap member in graph object using the variable node map and skip to the next quad . value of the listMap member using the variable list map .
    6. For each RDF triple in graph consisting of subject , predicate , and object :
      1. If property is predicate equals rdf:rest : rdf:first ,
        1. If object is a blank node , use the entry in graph.listMap indexed by list map has no subject , initializing member, create one and initialize it to a new an empty JSON object if necessary. Add .
        2. Initialize the nominalValue value of object the first member of the subject member of list map to the entry indexed by rest . result of the RDF to Object Conversion algorithm , passing object .
        3. Skip to Continue with the next quad RDF triple .
      2. If name is not null , predicate equals rdf:rest :
        1. If list map has no subject member, create one and defaultGraph.nodes does not contain initialize it to an entry for name , create a new entry for name from a new empty JSON object with key/value pair .
        2. Initialize the value of the @id rest and name represented in expanded member of the subject member of list map to object , which is either an absolute IRI form or blank node identifier .
        3. Set value as Continue with the entry from graph.nodes for next RDF triple .
      3. If node map does not have a subject , initializing it member, create one and initialize its value to a new JSON object with key/value pair consisting of a single member @id and whose value is set to subject represented .
      4. Reference the value of the subject member in expanded IRI form if necessary. node map using the variable node .
      5. If property is predicate equals rdf:type , and object is not a JSON-LD value , and the useRdfType an option is not present or false : Append object represented in expanded IRI form or blank node identifier , append object to the array value for of the key @type , creating an entry in value if necessary. Otherwise, if object is a typed value and the useNativeTypes option is set to true : Generate a converted value : member of node . If the literal's type is xsd:boolean , the converted value is true no such member exists, create one and initialize it to an array if the literal matches the value true or false if the literal matches the value false . If the literal's type whose only item is xsd:integer or xsd:double , try object . Finally, continue to convert the literal to a JSON number next RDF triple .
      6. If the conversion is successful, store the result in converted value , otherwise set converted node does not have an predicate member, create one and initialize its value to value . an empty array .
      7. Otherwise, do not perform a conversion. Set the converted value to the value . result of using the RDF to Object Conversion algorithm , passing object .
      8. Append the converted Add a reference to value to the to the array value for associated with the key, creating an entry in value if necessary. predicate member of node .
      9. Otherwise, if If object is rdf:nil : Let key be property expressed in expanded IRI form . Append an empty @list representation to the array value for key , creating an entry in value if necessary. Otherwise, Let key be property expressed in expanded IRI form and let object representation be object represented in expanded form as described in Value Expansion . If object is or a blank node , use the entry in graph.listMap indexed by object , initializing identifier it to might represent the head of a new JSON RDF list:
        1. If list map has no object if nesessary. Add member, create one and set its value to an entry for head with empty JSON object representation . .
        2. Append Set the head member of the object representation member of list map to a reference of value . This reference may be required later to replace the array value for key , creating an entry in value if necessary. the predicate member of node with a list object .
  5. For each name and graph object in graphs : graph map :
    1. Reference the value of the listMap member in graph object using the variable list map .
    2. For each key-value pair subject and - entry in of the value associated to the listMap member of graph where object :
      1. If entry has both not an head and an first keys: member it does not represent the head of a list . Continue with the next key-value pair.
      2. Set value to Reference the value of the head member in entry . using the variable value .
      3. Remove the entry for @id in member from value . .
      4. Add an entry to value for @list initialized member to a new value and initialize it to an array containing the value of the first from member of entry . .
      5. While entry has a key for the value associated with the rest : member of entry is not rdf:nil :
        1. Set rest to the value of the rest member of entry .
        2. Set entry to the value associated with the rest member of graph.listMap for entry.rest . list map .
        3. Add the value for entry.first associated with the first member of entry to the list array. @list member of value .
  6. Create array as Initialize an empty array . result .
  7. For each subject and entry node in defaultGraph.nodes default graph nodes ordered by subject : :
    1. Add entry to array . If graphs graph map has an entry for subject , add member:
      1. Add a property @graph in entry containing member to node and initialize its value to an empty array .
      2. Reference the nodeMap member of the subject member of graph map using the variable node map .
      3. For each key-value pair s - n in node map ordered entries from graphs[subject].nodes . by s , append n to the @graph member of node .
    2. Append node to result .
  8. Return result .

10.5 RDF to Object Conversion

This algorithm transforms an RDF literal to a JSON-LD value object and a RDF blank node or IRI to an JSON-LD node object .

General Solution

array This section is non-normative.

RDF literals are transformed to value objects as defined in the section Data Round Tripping whereas IRIs and blank node identifiers are transformed to node objects .

Algorithm

This algorithm takes as single input variable value that is converted to a JSON object .

  1. If value is an an IRI or a blank node identifier :
    1. If value equals rdf:nil return a new JSON object consisting of a single member @list whose value is set to an empty array . This is behavior is required by the Convert from RDF algorithm .
    2. Otherwise, return a new JSON object consisting of a single member @id whose value is set to value .
  2. Otherwise value is an RDF literal :
    1. Initialize a new empty JSON object result.
    2. Initialize converted value to value .
    3. Initialize type to null
    4. If the datatype IRI of value equals xsd:boolean , set converted value to true if the lexical form of value matches true , or false if it matches false .
    5. Otherwise, if the datatype IRI of value equals xsd:integer or xsd:double , try to convert the literal to a JSON number . If the conversion is successful, store the result in converted value .
    6. Otherwise, if value is a language-tagged string add a member @language to result and set its value to the language tag of value .
    7. Otherwise, set type to the datatype IRI of value , unless it equals xsd:string which is ignored.
    8. Add a member @value to result whose value is set to converted value .
    9. If type is not null , add a member @type to result whose value is set to type .
    10. Return result .

5.16.4 10.6 Data Round Tripping

When converting JSON-LD to RDF JSON-native types such as numbers and booleans are automatically coerced to xsd:integer , , xsd:double , , or xsd:boolean . . Implementers must MUST ensure that the result is in canonical lexical form . A canonical lexical form is a set of literals from among the valid set of literals for a datatype such that there is a one-to-one mapping between the canonical lexical form and a value in the value space as defined in [ XMLSCHEMA11-2 ]. In other words, every value must MUST be converted to a deterministic string representation.

The canonical lexical form of an integer , i.e., a number without fractions or a number coerced to xsd:integer , , is a finite-length sequence of decimal digits ( 0-9 ) with an optional leading minus sign; leading zeroes zeros are prohibited. To convert the number in JavaScript, implementers can use the following snippet of code:

Example 12 : Sample integer serialization implementation in JavaScript
(value).toFixed(0).toString()

The canonical lexical form of a double , i.e., a number with fractions or a number coerced to xsd:double , , consists of a mantissa followed by the character "E", "E", followed by an exponent. The mantissa must MUST be a decimal number. The exponent must MUST be an integer. Leading zeroes zeros and a preceding plus sign ( + ) are prohibited in the exponent. If the exponent is zero, it must be indicated by E0 . For the mantissa, the preceding optional plus sign is prohibited and the decimal point is required. Leading and trailing zeroes zeros are prohibited subject to the following: number representations must be normalized such that there is a single digit which is non-zero to the left of the decimal point and at least a single digit to the right of the decimal point unless the value being represented is zero. The canonical representation for zero is 0.0E0 . xsd:double 's value space is defined by the IEEE double-precision 64-bit floating point type [ IEEE-754-1985 ]; in JSON-LD the mantissa is rounded to 15 digits after the decimal point.

To convert the number in JavaScript, implementers can use the following snippet of code:

Example 13 : Sample floating point number serialization implementation in JavaScript
(value).toExponential(15).replace(/(\d)0*e\+?/,'$1E')
Note

When data such as decimals need to be normalized, JSON-LD authors should not use values that are going to undergo automatic conversion. This is due to the lossy nature of xsd:double values. Authors should instead use the expanded object form to set the canonical lexical form directly.

The canonical lexical form of the boolean values true and false are the strings true and false . .

When JSON-native number s, are type coerced, lossless data round-tripping can not be guaranted guaranteed as rounding errors might occur. Additionally, only literals typed as xsd:integer , , xsd:double , , and xsd:boolean are automatically converted back to their JSON-native counterparts in when converting from RDF .

Some JSON serializers, such as PHP's native implementation in some versions, backslash-escape the forward slash character. For example, the value http://example.com/ would be serialized as http:\/\/example.com\/ . This is problematic as other JSON parsers might not understand those escaping characters. There is no need to backslash-escape forward slashes in JSON-LD. To aid interoperability between JSON-LD processors, a JSON-LD serializer must not MUST NOT backslash-escape forward slashes.

6. 11. The Application Programming Interface

This API provides a clean mechanism that enables developers to convert JSON-LD data into a a variety of output formats that are often easier to work with in various programming languages. If a with. A conformant JSON-LD API is provided in a programming environment, Processor MUST implement the entirety of the following API must be implemented. API.

6.1 11.1 JsonLdProcessor

The JSON-LD processor Processor interface is the high-level programming structure that developers use to access the JSON-LD transformation methods.

The JSON-LD API signatures are the same across all programming languages. Due to the fact that asynchronous programming is uncommon in certain languages, developers may implement a processor with a synchronous interface instead. In that case, the callback parameter must not be included and the result must be returned as a return value instead. It is important to highlight that conformant JSON-LD processors must not MUST NOT modify the input parameters. If an error is detected, the callback is invoked passing a JsonLdError with the corresponding error code and processing is stopped.

] interface {
[Constructor]
interface JsonLdProcessor {
    void expand ((object or object[] or DOMString) input, JsonLdCallback callback, optional JsonLdOptions? options);
    void compact ((object or object[] or DOMString) input, (object or DOMString)? context, JsonLdCallback callback, optional JsonLdOptions? options);
    void flatten ((object or object[] or DOMString) input, (object or DOMString)? context, JsonLdCallback callback, optional JsonLdOptions? options);
};

6.1.1

Methods

compact

Compacts the given input using the context according to the steps in the Compaction Algorithm algorithm :

  1. If the passed input is a DOMString representing the IRI of a remote document, dereference it. If the retrieved document has a content type different than application/ld+json or application/json or if the document cannot be parsed as JSON, invoke the callback passing an loading document failed error.
  2. Initialize a new empty active context .
  3. If an expandContext has been passed, update the active context using the Context Processing algorithm , passing the expandContext as local context .
  4. If the input has been retrieved and the response has a content type application/json and an HTTP Link Header [ RFC5988 ] using the http://www.w3.org/ns/json-ld#context link relation, update the active context using the Context Processing algorithm , passing the context referenced in the HTTP Link Header as local context .
  5. Set expanded to the result of using the Expansion algorithm , passing the active context and input as element .
  6. Set compacted to the result of using the Compaction algorithm , passing context , expanded as element , and if passed, the compactArrays flag in options .
  7. Invoke callback , passing null for error and compacted for document .
Parameter Type Nullable Optional Description
input ( object or object[] or DOMString ) The JSON-LD object or array of JSON-LD objects to perform the compaction upon or an IRI referencing the JSON-LD document to compact.
context ( object or DOMString ) The context to use when compacting the input ; either in the form of an a JSON object or as IRI .
callback JsonLdCallback A callback that is called when processing is complete completed successfully on the given input . , or a fatal error prevented processing from completing.
options JsonLdOptions A set of options to configure the used algorithms such. algorithms. This allows, e.g., to set the input document's base IRI . This also includes the optimize flag, which, if set, will allow processor-specific optimization.
Return type: void
expand

Expands the given input according to the steps in the Expansion Algorithm algorithm :

  1. If the passed input is a DOMString representing the IRI of a remote document, dereference it. If the retrieved document has a content type different than application/ld+json or application/json or if the document cannot be parsed as JSON, invoke the callback passing an loading document failed error.
  2. Initialize a new empty active context .
  3. If an expandContext has been passed, update the active context using the Context Processing algorithm , passing the expandContext as local context .
  4. If the input has been retrieved and the response has a content type application/json and an HTTP Link Header [ RFC5988 ] using the http://www.w3.org/ns/json-ld#context link relation, update the active context using the Context Processing algorithm , passing the context referenced in the HTTP Link Header as local context .
  5. Set expanded to the result of using the Expansion algorithm , passing the active context and input as element .
  6. Invoke callback , passing null for error and expanded for document .
Parameter Type Nullable Optional Description
input ( object or object[] or DOMString ) The JSON-LD object or array of JSON-LD objects to perform the expansion upon or an IRI referencing the JSON-LD document to expand.
callback JsonLdCallback A callback that is called when processing is complete completed successfully on the given input . , or a fatal error prevented processing from completing.
options JsonLdOptions A set of options to configure the used algorithms such. This allows, e.g., to set the input document's base IRI .
Return type: void
flatten

Flattens the given input and compacts it using the passed context according to the steps in the Flattening Algorithm algorithm :

  1. If the passed input is a DOMString representing the IRI of a remote document, dereference it. If the retrieved document has a content type different than application/ld+json or application/json or if the document cannot be parsed as JSON, invoke the callback passing an loading document failed error.
  2. Initialize a new empty active context .
  3. If an expandContext has been passed, update the active context using the Context Processing algorithm , passing the expandContext as local context .
  4. If the input has been retrieved and the response has a content type application/json and an HTTP Link Header [ RFC5988 ] using the http://www.w3.org/ns/json-ld#context link relation, update the active context using the Context Processing algorithm , passing the context referenced in the HTTP Link Header as local context .
  5. Set expanded to the result of using the Expansion algorithm , passing the active context and input as element .
  6. Initialize an empty identifier map and a counter (set to 0 ) to be used by the Generate Blank Node Identifier algorithm .
  7. Set flattened to the result of using the Flattening algorithm , passing expanded as element , context , and if passed, the compactArrays flag in options (which is internally passed to the Compaction algorithm ).
  8. Invoke callback , passing null for error and flattened for document .
Parameter Type Nullable Optional Description
input ( object or object[] or DOMString ) The JSON-LD object or array of JSON-LD objects or an IRI referencing the JSON-LD document to flatten.
context ( object or DOMString ) The context to use when compacting the flattened input ; either in the form of an a JSON object or as IRI . If null is passed, the result will not be compacted but keept kept in expanded form.
callback JsonLdCallback A callback that is called when processing is complete completed successfully on the given input . , or a fatal error prevented processing from completing.
options JsonLdOptions A set of options to configure the used algorithms such. This allows, e.g., to set the input document's base IRI .
Return type: void

6.2 11.2 Callbacks

JSON-LD processors utilize callbacks in order to return exchange information in an asynchronous manner to calling with applications. This section details the parameters sent to of those callbacks.

6.2.1

JsonLdCallback

The JsonLdCallback is called when processing of an API method of JsonLdProcessor has been completed completed, either successfully or been terminated by an a fatal error.


callback

JsonLdCallback

=


void


(




JsonLdProcessingError

JsonLdError





error

,



object
or
object

[]


document


);

Callback JsonLdCallback Parameters
error of type JsonLdProcessingError JsonLdError
If the value is null , , then no error occurred. If the value is non- null , issue was detected during processing. Otherwise, a processing error occurred was detected and the details will be are contained within the error object.
document of type array of object or object
The processed JSON-LD document.

LoadContextCallback

The LoadContextCallback defines the callback that custom context loaders have to implement to be used to retrieve remote contexts.


callback

LoadContextCallback

=

void

(

DOMString

url
,
ContextLoadedCallback

callback

);
Callback LoadContextCallback Parameters
url of type DOMString
The URL of the remote context to load.
callback of type ContextLoadedCallback
The callback that is called when the remote context has been successfully loaded or an error preventing its loading has been detected.

ContextLoadedCallback

The ContextLoadedCallback is called in response to a call of the LoadContextCallback .


callback

ContextLoadedCallback

=

void

(

JsonLdError

error
,
DOMString

url
,
DOMString

context

);
Callback ContextLoadedCallback Parameters
error of type JsonLdError
If the value is null , then no issue was detected during processing. Otherwise, a processing issue was detected and the details are contained within the error object. All errors MUST have a JsonLdErrorCode of loading remote context failed .
url of type DOMString
The final URL of the loaded JSON-LD context. This is important to handle HTTP redirects properly.
context of type DOMString
The raw content of the retrieved JSON-LD context.

6.3 11.3 Data Structures

This section describes datatype definitions used within the JSON-LD API.

6.3.1

JsonLdOptions

The JsonLdOptions type is used to pass various options to the JsonLdProcessor methods.

{
dictionary JsonLdOptions {
    DOMString           base;
    boolean             compactArrays = true;
    LoadContextCallback loadContext;
    object or DOMString expandContext = null;
    DOMString           processingMode = "json-ld-1.0";
};

Dictionary JsonLdOptions Members
base of type DOMString
The Base IRI to use when expanding or compacting the document. This overrides the value of input if it is a IRI . If not specified and input is not an IRI , the base IRI defaults to the current document IRI if in a browser context, or the empty string if there is no document context.
Issue 223 : Feature at risk

The default value of this option implies that all IRIs that cannot be compacted otherwise are transformed to relative IRIs during compaction. To avoid that data is being lost, developers thus have to store the base IRI along with the compacted document. This might be problematic in practice and thus the default behavior might be changed in future. Furthermore, the relationship of this option to the @base keyword (which is at risk) should be further investigated.

compactArrays of type boolean , defaulting to true
If set to true , the JSON-LD processor replaces arrays with just one element with that element during compaction. If set to false , all arrays will remain arrays even if they have just one element.
expandContext of type object or DOMString , defaulting to null
A context that is used to initialize the active context when expanding a document.
optimize loadContext of type boolean , defaulting to false LoadContextCallback
If set to true , the JSON-LD processor is allowed to optimize the output The callback of the Compaction Algorithm context loader to produce even compacter representations. The algorithm for compaction optimization is beyond the scope of this specification and thus be used to retrieve remote contexts. If specified, it MUST be used to retrieve remote contexts; otherwise, if not defined. Consequently, different implementations may specified, the processor's built-in context loader MUST implement different optimization algorithms. be used.
useNativeTypes processingMode of type boolean DOMString , defaulting to true "json-ld-1.0"
If set to true json-ld-1.0 , the JSON-LD processor will try to convert typed values to JSON native types instead of using Processor MUST produce exactly the expanded object form when converting from RDF . xsd:boolean values will be converted to true or false . xsd:integer and xsd:double values will be converted to JSON numbers . useRdfType of type boolean , defaulting to false same results as the algorithms defined in this specification. If set to true , another value, the JSON-LD processor will use Processor is allowed to extend or modify the expanded rdf:type IRI as algorithms defined in this specification to enable application-specific optimizations. The definition of such optimizations is beyond the property instead scope of this specification and thus not defined. Consequently, different implementations MAY implement different optimizations. Developers MUST NOT define modes beginning with @type json-ld when converting from RDF . as they are reserved for future versions of this specification.
6.3.2 JsonLdProcessingError

JsonLdError

Issue 153 Developers should note that the details of error handling are being actively debated.

The JsonLdProcessingError JsonLdError type is used to report processing errors to a JsonLdCallback .

{
dictionary JsonLdError {
    JsonLdErrorCode code;
    DOMString?      message;
};

Dictionary JsonLdProcessingError JsonLdError Members
code of type JsonLdErrorCode
a string representing the particular error type, as described in the various algorithms in this document.
message of type DOMString , nullable
an optional error message containing additional debugging information. The specific contents of error messages are outside the scope of this specification and thus implementation dependent. specification.
6.3.3

JsonLdErrorCode

The JsonLdErrorCode represent represents the collection of valid JSON-LD error codes.

{ "", "", ""
enum JsonLdErrorCode {
    "loading document failed",
    "list of lists",
    "invalid @index value",
    "conflicting indexes",
    "invalid @id value",
    "invalid local context",
    "loading remote context failed",
    "invalid remote context",
    "recursive context inclusion",
    "invalid base IRI",
    "invalid vocab mapping",
    "invalid default language",
    "keyword redefinition",
    "invalid term definition",
    "invalid reverse property",
    "invalid IRI mapping",
    "cyclic IRI mapping",
    "invalid keyword alias",
    "invalid type mapping",
    "invalid language mapping",
    "colliding keywords",
    "invalid container mapping",
    "invalid type value",
    "invalid value object",
    "invalid value object value",
    "invalid language-tagged string",
    "invalid language-tagged value",
    "invalid typed value",
    "invalid set or list object",
    "invalid language map value",
    "compaction to list of lists",
    "invalid reverse property map",
    "invalid @reverse value",
    "invalid reverse property value"

};

JSON-LD ]
Enumeration description
INVALID_SYNTAX loading document failed The document could not be loaded or parsed as JSON.
list of lists A violation list of lists was detected. List of lists are not supported in this version of JSON-LD due to the grammar as defined by algorithmic complexity associated with conversion to RDF.
invalid @index value An @index member was encountered whose value was not a string .
conflicting indexes Multiple conflicting indexes have been found for the JSON-LD syntax specification [ same node.
invalid @id value An @id member was encountered whose value was not a string .
invalid local context In invalid local context was detected.
LOAD_ERROR loading remote context failed There was a problem encountered loading a remote context.
LIST_OF_LISTS_DETECTED invalid remote context No valid context document has been found for a referenced, remote context.
recursive context inclusion A list cycle in remote context inclusions has been detected.
invalid base IRI An invalid base IRI has been detected, i.e., it is neither an absolute IRI nor null .
invalid vocab mapping An invalid vocabulary mapping has been detected, i.e., it is neither an absolute IRI nor null .
invalid default language The value of lists the default language is not a string or null and thus invalid.
keyword redefinition A keyword redefinition has been detected.
invalid term definition An invalid term definition has been detected.
invalid reverse property An invalid reverse property definition has been detected.
invalid IRI mapping A local context contains a term that has an invalid or missing IRI mapping .
cyclic IRI mapping A cycle in IRI mappings has been detected.
invalid keyword alias An invalid keyword alias definition has been encountered.
invalid type mapping An @type member in a term definition was encountered whose value could not be expanded to an absolute IRI .
invalid language mapping An @language member in a term definition was encountered whose value was neither a string nor null and thus invalid.
colliding keywords Two properties which expand to the same keyword have been detected. List of lists This might occur if a keyword and an an alias thereof are used at the same time.
invalid container mapping An @container member was encountered whose value was not supported in this version one of JSON-LD due to the algorithmic complexity following strings : @list , @set , or @index .
invalid type value An invalid value for an @type member has been detected, i.e., the value was neither a string nor an array of strings .
invalid value object A value object with disallowed members has been detected.
invalid value object value An invalid value for the @value member of a value object has been detected, i.e., it is neither a scalar nor null .
invalid language-tagged string A language-tagged string with an invalid language value was detected.
invalid language-tagged value A number , true , or false with an associated language tag was detected.
invalid typed value A typed value with conversion an invalid type was detected.
invalid set or list object A set object or list object with disallowed members has been detected.
invalid language map value An invalid value in a language map has been detected. It has to RDF. be a string or an array of strings .
compaction to list of lists The compacted document contains a list of lists as multiple lists have been compacted to the same term.
invalid reverse property map An invalid reverse property map has been detected. No keywords apart from @context are allowed in reverse property maps.
invalid @reverse value An invalid value for an @reverse member has been detected, i.e., the value was not a JSON object .
invalid reverse property value An invalid value for a reverse property has been detected. The value of an inverse property must be a node object .

A. Acknowledgements

This section is non-normative.

A large amount of thanks goes out to the JSON-LD Community Group participants who worked through many of the technical issues on the mailing list and the weekly telecons - of special mention are Niklas Lindström, François Daoust, Lin Clark, and Zdenko 'Denny' Vrandečić. The editors would like to thank Mark Birbeck, who provided a great deal of the initial push behind the JSON-LD work via his work on RDFj. The work of Dave Lehn and Mike Johnson are appreciated for reviewing, and performing several implementations of the specification. Ian Davis is thanked for his work on RDF/JSON. Thanks also to Nathan Rixham, Bradley P. Allen, Kingsley Idehen, Glenn McDonald, Alexandre Passant, Danny Ayers, Ted Thibodeau Jr., Olivier Grisel, Josh Mandel, Eric Prud'hommeaux, David Wood, Guus Schreiber, Pat Hayes, Sandro Hawke, and Richard Cyganiak or their input on the specification.

B. References

B.1 Normative references

[IEEE-754-1985]
IEEE. IEEE Standard for Binary Floating-Point Arithmetic. See URL: http://standards.ieee.org/reading/ieee/std_public/description/busarch/754-1985_desc.html
[JSON-LD]
The JSON-LD Syntax Manu Sporny, Gregg Kellogg, Markus Lanthaler Lanthaler, Editors. World Wide Web Consortium (work in progress). 22 May 2012. Editor's Draft. This edition of the JSON-LD Syntax specification is http://json-ld.org/spec/ED/json-ld-syntax/20120522/. The latest edition of the JSON-LD Syntax is available at http://json-ld.org/spec/latest/json-ld-syntax/ [RDF-CONCEPTS] RDF 1.1 Concepts and Abstract Syntax JSON-LD 1.0 . Richard Cyganiak, David Wood, Editors. World Wide Web Consortium W3C Editor's Draft (work in progress). 30 May 2012. Editor's Draft. This edition of the JSON-LD Syntax specification is http://www.w3.org/TR/2011/WD-rdf11-concepts-20110830/. The latest edition of the JSON-LD Syntax URL: http://json-ld.org/spec/latest/json-ld-syntax/ is available at http://www.w3.org/TR/rdf11-concepts/
[RDF-SCHEMA]
[RDF-MT]
Dan Brickley; Ramanathan V. Guha. Patrick Hayes. RDF Vocabulary Description Language 1.0: RDF Schema. Semantics . 10 February 2004. W3C Recommendation. URL: http://www.w3.org/TR/2004/REC-rdf-schema-20040210 http://www.w3.org/TR/2004/REC-rdf-mt-20040210
[RFC2119]
S. Bradner. Key words for use in RFCs to Indicate Requirement Levels. March 1997. Internet RFC 2119. URL: http://www.ietf.org/rfc/rfc2119.txt
[RFC3986]
T. Berners-Lee; R. Fielding; L. Masinter. Uniform Resource Identifier (URI): Generic Syntax. Syntax . January 2005. Internet RFC 3986. URL: http://www.ietf.org/rfc/rfc3986.txt
[RFC3987]
M. Dürst; M. Suignard. Internationalized Resource Identifiers (IRIs). (IRIs) . January 2005. Internet RFC 3987. URL: http://www.ietf.org/rfc/rfc3987.txt
[RFC4627]
D. Crockford. The application/json Media Type for JavaScript Object Notation (JSON) . July 2006. Internet RFC 4627. URL: http://www.ietf.org/rfc/rfc4627.txt
[WEBIDL]
[RFC5988]
M. Nottingham. Web IDL Linking . October 2010. Internet RFC 5988. URL: http://www.ietf.org/rfc/rfc5988.txt
[WEBIDL]
Cameron McCormack, Editor. World Wide Web Consortium. IDL. 19 April 2012. W3C Candidate Recommendataion. This edition of Web IDL is http://www.w3.org/TR/2012/CR-WebIDL-20120419/. Recommendation (work in progress). URL: http://www.w3.org/TR/2012/CR-WebIDL-20120419/ . The latest edition of Web IDL is available at http://dev.w3.org/2006/webapi/WebIDL/ http://www.w3.org/TR/WebIDL/
[XMLSCHEMA11-2]
Henry S. Thompson; Thompson et al. W3C XML Schema Definition Language (XSD) 1.1 Part 2: Datatypes. Datatypes . 5 April 2012. W3C Recommendation Recommendation. URL: http://www.w3.org/TR/2012/REC-xmlschema11-2-20120405/

B.2 Informative references

[BCP47]
A. Phillips; M. Davis. Tags for Identifying Languages . September 2009. IETF Best Current Practice. URL: http://tools.ietf.org/html/bcp47
[ECMA-262]
ECMAScript Language Specification. June 2011. URL: http://www.ecma-international.org/publications/standards/Ecma-262.htm
[JSON-LD-TESTS]
JSON-LD Test Suite (work in progress).
[TURTLE-TR]
[RDF11-CONCEPTS]
Richard Cyganiak, David Wood, Editors. RDF 1.1 Concepts and Abstract Syntax. 15 January 2013. W3C Working Draft (work in progress). URL: http://www.w3.org/TR/2013/WD-rdf11-concepts-20130115/ . The latest edition is available at http://www.w3.org/TR/rdf11-concepts/
[TURTLE]
Eric Prud'hommeaux, Gavin Carothers. Carothers, Editors. Turtle: Terse RDF Triple Language. 09 August 2011. 19 February 2013. W3C Working Draft. Candidate Recommendation (work in progress). URL: http://www.w3.org/TR/2011/WD-turtle-20110809/ http://www.w3.org/TR/2013/CR-turtle-20130219/ . The latest edition is available at http://www.w3.org/TR/turtle/