From 3ecb2294c71119509e7df66bbdb15dd4b8a2882a Mon Sep 17 00:00:00 2001
From: Gregg Kellogg JSON-LD mostly uses the JSON syntax [[RFC8259]] along with
various micro-syntaxes based on XML Schema datatypes [[XMLSCHEMA11-2]].
However, it has become increasingly common to include JSON within
- a script element
+ a script element
within an HTML document [[HTML]],
as described in .
As not all processors operate in an environment which can include HTML,
@@ -1111,33 +1111,10 @@ The algorithm extracts the text content a
JSON-LD script element into a dictionary or array of dictionaries.
A JSON-LD script element is a script element
- within an HTML [[HTML]] document with the The algorithm takes a single required input variable: source,
@@ -5131,21 +5108,18 @@ Processor Levels
Algorithm
then the processor MUST NOT do a further dereference, and
context is set to the
previously established internal representation.
- text/html
:
-
-
- type
application/ld+json;profile=http://www.w3.org/ns/json-ld#context
,
- set source to the textContent
- of the first element found with that type.type
application/ld+json
,
- set source to the textContent
- of the first element found with that type.http://www.w3.org/ns/json-ld#context
for profileExtract Script Content Algorithm
type
attribute set to
+ within an HTML [[HTML]] document with the type attribute set to
application/ld+json
.The JsonLdProcessor Interface
-
+ is a string representing the IRI of a remote document, await and dereference it as remote document
+ using LoadDocumentCallback, passing input
+ for url,
+ the extractAllScripts option for extractAllScripts.
text/html
,
- and the processor is a pure JSON Processor
- reject the promise passing a loading document failed error.application/json
,
- application/ld+json
,
- nor any other media type using a
- +json
suffix as defined in [[RFC6839]],
- reject the promise passing a loading document failed error.null
.
If set, the base option from options overrides the base IRI.The JsonLdProcessor Interface
passing the expandContext as local context.
If expandContext is a dictionary having an @context
member,
pass that member's value instead.http://www.w3.org/ns/json-ld#context
link relation
- and a Content-Type of application/json
- or any media type with a +json
suffix as defined in [[RFC6839]]
- except application/ld+json
,
+ application/ld+json
- or text/html
.
- 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 code is set to multiple context link headers
- and processing is terminated.text/html
,
- the processor is not a pure JSON Processor
- and the passed input is
- a string representing the IRI of a remote document,
- extract the content of the JSON-LD script element(s) into original input:
-
-
- type
application/ld+json
,
- reject promise passing an invalid script element error.
- Set original input to the result of the Extract Script Content algorithm,
- using source.false
,
- locate the first JSON-LD script element in input,
- and set source to its textContent, if found.
- Set original input to the result of the Extract Script Content algorithm,
- using source.
- If no JSON-LD script element is found, set original input to a new empty array.
-
- Remote Document and Context Retrieval
This section details the parameters of that callback
and the data structure used to return the retrieved context.
The LoadDocumentCallback defines a callback that custom document loaders - have to implement to be used to retrieve remote documents and contexts.
+ have to implement to be used to retrieve remote documents and contexts. + Upon successful completion, the callback returns a Promise containing a RemoteDocument. + On failure, the Promise is rejected with an appropriate error code.All errors result in the Promise being rejected with a JsonLdError - whose code is set to loading document failed - or multiple context link headers - as described in the next section.
+The following algorithm describes the default callback and places + requirements on implementations of the callback.
+ +application/ld+json
+ followed by application/json
.
+
+ If requestProfile is set,
+ it MUST be added as a profile on application/ld+json
.
Processors MAY include other media types using a +json
suffix as defined in [[RFC6839]].
A full Processor MUST include text/html
at any preference level.
303
"See Other" redirects
+ as discussed in [[?cooluris]]).application/json
+ or any media type with a +json
suffix as defined in [[RFC6839]]
+ except application/ld+json
,
+ and the response has an HTTP Link Header [[RFC8288]] using the http://www.w3.org/ns/json-ld#context
link relation,
+ set contextUrl to the associated href
.
+ 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 code is set to multiple context link headers
+ and processing is terminated.
Processors MAY transform document to the internal representation + using the Extract Script Content algorithm.
+The HTTP Link Header is ignored for documents served as application/ld+json
+ or text/html
.
text/html
:
+ If no such element is found, + or the located element is not a JSON-LD script element, + the promise is rejected with a JsonLdError whose code is set to loading document failed + and processing is terminated.
application/ld+json
along with the value of the
+ profile option, if found.false
,
+ set source to the textContent
+ of the first JSON-LD script element in document.
+ If no such element is found, + or the located element is not a JSON-LD script element, + the promise is rejected with a JsonLdError whose code is set to loading document failed + and processing is terminated.
false
,
+ the promise is rejected with a JsonLdError whose code is set to loading document failed
+ and processing is terminated.true
,
+ set document to a new empty array.
+ For each JSON-LD script element in input:
+ application/json
,
+ application/ld+json
,
+ nor any other media type using a
+ +json
suffix as defined in [[RFC6839]],
+ reject the promise passing a loading document failed error.profile
parameter,
+ and any contextUrl.A custom LoadDocumentCallback set via the + documentLoader option might be used + to maintain a local cache of well-known context documents or to implement + application-specific URL protocols.
+The LoadDocumentOptions type is used to pass various options + to the LoadDocumentCallback.
+ + + +true
,
+ when extracting JSON-LD script elements from HTML,
+ unless a specific fragment identifier is targeted,
+ extracts all encountered JSON-LD script elements using an array form, if necessary.text/html
,
+ this option determines the profile to use for selecting a JSON-LD script elements.profile
parameter.
+ (See IANA Considerations in [[JSON-LD11]]).profile
parameter
+ retrieved as part of the original contentType.type
attribute.The following is a list of issues open at the time of publication.
-Define a "streaming profile" for JSON-LD to help parse data from a stream, rather than require the entire document to be in memory. Also to generate documents that can be so streamed. This would aid in using JSON-LD as a dataset dump format where there are a very large number of quads.
-What if a @context URL response is HTML? - The HTML-based response has the value of potentially providing documentation for the contained context, but we lack a few things and/or need to clarify others. -
More compact @prefix.
application/ld+json;profile=http://www.w3.org/ns/json-ld#context
,
or application/ld+json
is used as the context for further processing.
This allows a mechanism for documenting the content of a context using HTML.
+ The LoadDocumentCallback defines a callback that custom document loaders have to implement to be used to retrieve remote documents and contexts. - Upon successful completion, the callback returns a Promise containing a RemoteDocument. - On failure, the Promise is rejected with an appropriate error code.
+ The callback returns a Promise resolving to a RemoteDocument. + On failure, the Promise is rejected with an appropriate error code.