From 2b917877b5447dc550709eb27b91f46887742808 Mon Sep 17 00:00:00 2001
From: Anatoly Scherbakov Features
strings, numbers, booleans, and null to describe
the data represented by a JSON document. Algorithms act on this
internal representation with API entry points responsible for
- transforming between the concrete and internal representations.
JSON-LD uses contexts to allow Linked Data to be expressed in a way that is specifically tailored to a particular @@ -5711,6 +5713,30 @@
Details about transforming to and from a given serialization format + have been abstracted so that other specifications can define + serialization and deserialization requirements for their specific formats. + The algorithm is now more explicit about serializing and deserializing + to the internal representation. + See marked changes here and in the following locations:
+ +For more information, refer to issue 605.
+Methods resolving a {{Promise}} with the internal representation + MUST either + map it to the datatype used by the implementation, as described in , + or serialize it to JSON (or another appropriate serialization format) + as described in .
+/* * The JsonLd interface is created to expose the JsonLdProcessor interface. @@ -5757,18 +5783,18 @@Algorithm
an@context
entry is added to the map result.-
- Create a new {{Promise}} promise and return it. +
- Create a new {{Promise}} promise and return it. The following steps are then deferred.
-- If the provided input +
- If the provided input is a RemoteDocument, initialize remote document to input.
-- Otherwise, if the provided input +
- Otherwise, if the provided input is a string representing the IRI of a remote document, await and dereference it as remote document using LoadDocumentCallback, passing input for {{LoadDocumentCallback/url}}, and the {{JsonLdOptions/extractAllScripts}} option from options for extractAllScripts.
-- Set expanded input to the result of +
- Set expanded input to the result of using the expand() method using either remote document or input @@ -5777,45 +5803,47 @@
-Algorithm
and options, with {{JsonLdOptions/ordered}} set tofalse
, and {{JsonLdOptions/extractAllScripts}} defaulting tofalse
.- Set context base to the {{RemoteDocument/documentUrl}} +
- Set context base to the {{RemoteDocument/documentUrl}} from remote document, if available, otherwise to the {{JsonLdOptions/base}} option from options.
-- If context is a map +
- If context is a map having an
-@context
entry, set context to that entry's value, otherwise to context.- Initialize active context +
- Initialize active context to the result of the Context Processing algorithm passing a new empty context as active context context as local context, and context base as base URL.
-- Set base IRI in active context to the {{JsonLdOptions/base}} option from options, if set; +
- Set base IRI in active context + to the {{JsonLdOptions/base}} option from options, if set; otherwise, if the compactToRelative option is true, to the IRI of the currently being processed document, if available; otherwise to
-null
.- Set compacted output to the result of using the Compaction algorithm, - using active context, +
- Set compacted output to the result of + using the Compaction algorithm, + with active context,
-null
for active property, expanded input as element, and the {{JsonLdOptions/compactArrays}} and {{JsonLdOptions/ordered}} flags from options.-
- If compacted output is an empty array, +
- If compacted output is an empty array, replace it with a new map.
-- Otherwise, if compacted output is an array, +
- Otherwise, if compacted output is an array, replace it with a new map with a single entry whose key is the result of IRI compacting `@graph` and value is compacted output.
-- If context was not
null
, +- If context was not
null
, add an@context
entry to compacted output and set its value to the provided context.- Resolve the promise with compacted output - transforming compacted output from the - internal representation to a JSON serialization.
+- Resolve the promise with compacted output
+ transforming compacted output from the + internal representation to a JSON serialization.
@context
entry,
pass that entry's value instead for local context.@graph
entry,
set expanded output that value.null
,
+ null
,
set expanded output to an empty array.false
.When the value is a JsonLdRecord or sequence of JsonLdRecords, - the values are taken as their equivalent internal representation values, + the values are taken as their equivalent internal representation values, where a JsonLdRecord is equivalent to a map, and a sequence of JsonLdRecords is equivalent to an array of maps. The map entries are converted to their equivalents @@ -6108,11 +6138,127 @@
When the value is a JsonLdRecord or sequence of JsonLdRecords, - the values are taken as their equivalent internal representation values, + the values are taken as their equivalent internal representation values, where a JsonLdRecord is equivalent to a map, and a sequence of JsonLdRecords is equivalent to an array of maps. The map entries are converted to their equivalents in [[INFRA]].
+ ++ USVString, + JsonLdRecord, + sequence, + and other types defined in [[WebIDL]] and [[INFRA]], and used above as input and output types for + JsonLdProcessor functions, comprise the data structure known + as the internal representation. + JSON-LD algorithms are defined against those types. +
+ ++ Implementations map [[WebIDL]] and [[INFRA]] types to types specific to the + programming language in use. For instance: +
+ +WebIDL Type | +INFRA Type | +JavaScript Type | +Python Type | +
---|---|---|---|
USVString |
+ String |
+ String |
+ str |
+
JsonLdRecord | +Map |
+ Object |
+ dict |
+
sequence | +list |
+ Array |
+ list |
+
long |
+ integer [[?XMLSCHEMA11-2]] |
+ Number |
+ int |
+
double |
+ double [[?XMLSCHEMA11-2]] |
+ Number |
+ float |
+
boolean |
+ boolean |
+ Boolean |
+ bool |
+
null |
+ null |
+ Null |
+ None |
+
+ The table above is only provided as an example. + The mappings used for a particular implementation are out of scope for + this specification. +
+This section defines the requirements for serializing and deserializing
+ JSON from and to the internal representation, as appropriate,
+ based on the provided or requested Content-Type.
+ A Content-Type of application/json
,
+ or media type with a +json
suffix as defined in [[RFC6839]]
+ MUST serialize or deserialize to a format consistent with the JSON Grammar
+ as specified in [[RFC8259]].
This specification does not define serializations of the internal representation + for other media types, which may be defined by other specifications.
+ +See + for details on extracting JSON from HTML.
+ +[=ToString=]
);
+ If multiple HTTP Link Headers using the http://www.w3.org/ns/json-ld#context
link relation are found,
the promise is rejected with a JsonLdError whose {{JsonLdError/code}} is set to multiple context link headers
and processing is terminated.
Processors MAY transform document to the internal representation.
+Processors MAY transform a document to the internal representation, + as described in .
The HTTP Link Header is ignored for documents served as application/ld+json
,
text/html
, or application/xhtml+xml
.
Details about transforming to and from a given serialization format have been abstracted so that other specifications can define serialization and deserialization requirements for their specific formats. @@ -5731,7 +5731,7 @@
For more information, refer to issue 605.
Methods resolving a {{Promise}} with the internal representation
+ Methods resolving a {{Promise}} with the internal representation
MUST either
map it to the datatype used by the implementation, as described in ,
or serialize it to JSON (or another appropriate serialization format)
@@ -5841,7 +5841,7 @@ This section defines the requirements for serializing and deserializing
JSON from and to the internal representation, as appropriate,
@@ -6257,7 +6257,7 @@ Algorithm
to the provided context.
-
+
transforming compacted output from the
internal representation to a JSON serialization.Algorithm
set expanded output to an array containing only expanded output.
+
transforming expanded output from the
internal representation to a JSON serialization.Algorithm
otherwise to null
.
+
transforming flattened output from the
internal representation to a JSON serialization.Algorithm
Serialize RDF as JSON-LD Algorithm method
using dataset
and options.
+
transforming expanded output from the
internal representation to a JSON serialization.Internal Representation in Implementations
Serialization and Deserialization
-
+
Serialization and Deserialization
- This section left intentially blank.
+ This section left intentially blank.
Change log
as described in Candidate Correction 4.Algorithm
is used instead of looking at the HTTP Link Header directly. For the sake of simplicity, none of the algorithms
in this document mention this directly.
Details about transforming to and from a given serialization format have been abstracted so that other specifications can define @@ -5731,7 +5731,7 @@
For more information, refer to issue 605.
Methods resolving a {{Promise}} with the internal representation
+ Methods resolving a {{Promise}} with the internal representation
MUST either
map it to the datatype used by the implementation, as described in ,
or serialize it to JSON (or another appropriate serialization format)
@@ -5841,7 +5841,7 @@ This section defines the requirements for serializing and deserializing
JSON from and to the internal representation, as appropriate,
@@ -6257,7 +6257,7 @@ Algorithm
to the provided context.
-
+
transforming compacted output from the
internal representation to a JSON serialization.Algorithm
set expanded output to an array containing only expanded output.
+
transforming expanded output from the
internal representation to a JSON serialization.Algorithm
otherwise to null
.
+
transforming flattened output from the
internal representation to a JSON serialization.Algorithm
Serialize RDF as JSON-LD Algorithm method
using dataset
and options.
+
transforming expanded output from the
internal representation to a JSON serialization.Internal Representation in Implementations
Serialization and Deserialization
-
+
Serialization and Deserialization
- This section left intentially blank.
+ This section left intentially blank.
Change log
as described in Candidate Correction 4.