diff --git a/spec/index.html b/spec/index.html index 178c361..f92f06c 100644 --- a/spec/index.html +++ b/spec/index.html @@ -221,7 +221,7 @@ to represent information serialized as JSON, including Linked Data. This document defines how to serialize linked data - in YAML documents. + in YAML. Moreover, it registers the application/ld+yaml media type.

@@ -243,16 +243,13 @@

Introduction

Since YAML is more expressive than JSON, both in the available data types and in the document structure - (see I-D.ietf-yaml-mediatypes), - this document identifies constraints on YAML documents - such that they can be used to represent JSON-LD documents. + (see [[I-D.ietf-httpapi-yaml-mediatypes]]), + this document identifies constraints on YAML + such that it can be used to represent JSON-LD documents.

-

A YAML-LD document complies with this specification if ...

-

Define YAML-LD document somewhere.

-

This specification makes use of the following namespace prefixes:

@@ -283,9 +280,169 @@

Introduction

Basic Concepts

-

FIXME.

+

+ To ease writing and collaborating on JSON-LD documents, it is a common practice + to serialize them as YAML. + This requires a registered media type, not only to enable content negotiation + of linked data documents in YAML, but also to define the expected behavior of + applications that process these documents, including fragment identifiers and + interoperability considerations. +

+ +

+ This is because YAML is more flexible than JSON: +

+ +
+
+

Core Requirements

+ +

+ A YAML-LD stream is a YAML stream of YAML-LD documents. + Note that each document in a stream is independent + from the others; + each one has its own context, YAML directives, + named anchors, and so on. +

+

+ A YAML-LD document is a [[YAML]] document + that can be interpreted as Linked Data [[LINKED-DATA]]. +

+

+ It MUST be encoded in UTF-8, to ensure interoperability with [[JSON]]. +

+

+ Comments in YAML-LD documents + are treated as white space. + This behavior is consistent with other + Linked Data serializations like [[TURTLE]]. + See Interoperability considerations of [[I-D.ietf-httpapi-yaml-mediatypes]] + for more details. +

+

+ Since named anchors are a serialization detail, + such names + MUST NOT be used to convey relevant information, + MAY be altered when processing the document, + and MAY be dropped when interpreting the document as JSON-LD. +

+

+ A YAML-LD document MAY contain named anchors and alias nodes, + but its representation graph MUST NOT contain cycles. + When interpreting the document as JSON-LD, + alias nodes MUST be resolved by value to their target nodes. +

+

+ Example: The following YAML-LD document + contains alias nodes for the `{"@id": "countries:ITA"}` object: + + ```yaml + %YAML 1.2 + --- + "@context": + "@vocab": "http://schema.org/" + "countries": "http://publication.europa.eu/resource/authority/country/" + "@graph": + - &ITA + "@id": countries:ITA + - "@id": http://people.example/Homer + name: Homer Simpson + nationality: *ITA + - "@id": http://people.example/Lisa + name: Lisa Simpson + nationality: *ITA + ``` + While the representation graph (and eventually the in-memory representation + of the data structure, e.g., a Python dictionary or a Java hashmap) will still + contain references between nodes, the JSON-LD serialization will not. + + ```json + { + "@context": { + "@vocab": "http://schema.org/", + "countries": "http://publication.europa.eu/resource/authority/country/" + }, + "@graph": [ + { + "@id": "countries:ITA" + }, + { + "@id": "http://people.example/Homer", + "full_name": "Homer Simpson", + "country": { + "@id": "countries:ITA" + } + }, + { + "@id": "http://people.example/Lisa", + "full_name": "Lisa Simpson", + "country": { + "@id": "countries:ITA" + } + } + ] + } + ``` +

+

Security Considerations

@@ -423,5 +580,96 @@

Examples

+
+

REMOVE THIS SECTION BEFORE PUBLICATION.

+ +

FAQ

+ + #### Why does YAML-LD not preserve comments? +

+ [[JSON]] (and hence [[JSON-LD11]]) does not support comments, + and other Linked Data serialization formats + that support comments (such as [[TURTLE]]) + do not provide a means to preserve them + when processing and serializing the document + in other formats. + The proposed behavior is thus consistent with + other implementations. + + While YAML-LD could define a specific predicate for comments, + that is insufficient because, for example, + the order of keywords is not preserved in JSON, so the + comments could be displaced. + This specification does not provide a means for preserving + YAML comments after a JSON serialization. + + ```yaml + # First comment + "@context": "http://schema.org" + + # Second comment + givenName: John + ``` + + Transforming the above entry into a JSON-LD document + results in: + + ```json + { + "@context": "http://schema.org", + "givenName": "John" + } + ``` + + + #### Why does YAML-LD not extend the JSON-LD data model ? +

+ [[JSON]] only represents simple trees while [[YAML]] can support + rooted, directed graphs with references and cycles. + + The above structures cannot be preserved when serializing + to JSON-LD and - with respect to cycles - the serialization + will fail. + + Programming languages such as Java and Python already support + YAML representation graphs, but these implementations may behave + differently. + In the following example, `&value` references the value + of the keyword `value`. + + ```yaml + value: &value 100 + valve1: + temperature: &temp100C + value: *value + unit: degC + valve2: + temperature: *temp100C + ``` + + Processing this entry in Python, I get the following + structure that preserve the references to + mutable objects (e.g., the `temperature` dict) + but not to scalars (e.g., the `value` keyword). + + ```python + temperature = { "value": 100, "unit": "degC" } + document = { + "value": 100, + "valve1": { "temperature": temperature }, + "valve2": { "temperature": temperature } + } + ``` + + Since all these implementations pre-date this + specification, some more interoperable choices include the following: + + * forbidding cycles in YAML-LD documents + * considering all references in YAML-LD as static, + i.e., a shorthand way to repeat specific patterns + +

+
+