-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Serializing JSON or YAML literal in YAML-LD #36
Comments
One stated goal is to be able to use something like The YAML examples cited above are generated essentially by |
It seems to be that the two YAML snippets above serialize to the same JSON (and this is confirmed by a quick test on https://www.convertjson.com/yaml-to-json.htm), so I don't understand where the issue is. 🤔 |
It’s probably a more a more philosophical question: Must a JSON Literal necessarily have the form of JSON? |
It's also a pragmatic question:
|
I just learn now about JSON Literals... I think it is a very complex feature if you see it as a literal, because even JSON parsers will not treat it as you might expect. For example, a JSON Literal with duplicate keys will not be treated as literal by generic JSON parsers: {
"@context": {
"@version": 1.1,
"e": {
"@id": "http://example.com/vocab/json",
"@type": "@json"
}
},
"e": {
"a": "ciao",
"a": 1
}
} will result in an entry with the last (or the first, it's actually implementation dependent) removed. {
"@context": { ... },
"e": {
"a": 1
}
} |
@ioggstream https://w3c.github.io/json-ld-syntax/#the-rdf-json-datatype says "The lexical space This is not an optional feature. It's part of the JSON-LD spec, so it must be supported in YAML-LD. I provided a real-world use case for it: GraphDB connectors for Lucene, SOLR, Elastic (https://graphdb.ontotext.com/documentation/10.0/connectors.html#full-text-search-and-aggregation-connectors) |
The JSON-LD Literal definition is written to allow a variation in representation. The JCS C14N considerations only come into play when describing the representation within RDF Triples. Similar to The JSON-LD spec says non-normatively that values of |
@VladimirAlexiev said:
Then converting to RDF triples; a given serialization may have different ways of representation that. The JSON-LD from RDF algorithm describes the mechanism to use when transforming a triple containing an RDF Literal into JSON-LD.
Two different things. A JSON-LD processor may see JSON-LD with an explicit value of type
I think we need demonstrate a need here. The |
@VladimirAlexiev Afaik JSON grammar allows duplicate keys. You need JCS to forbid duplicate keys
What do you mean with "JSON subset"? If you mean something like the "internal representation" than its feasible. Otherwise I think that we can only check that the representation graph maps to the expected JSON literal when serialised in JSON. |
No, I believe this has been addressed by RFC8259:
Not a MUST, but that is because of concerns over backwards compatibility. The interoperation of when duplicate keys are present is unspecified, as different implementations do different things. Also JCS / RFC8785 prohibits objects from having duplicate keys:
|
Does JSON-LD use JCS or JSON? |
With regard to JSON Literals, the spec uses JCS. IIRC, the spec is silent on duplicate keys, and as noted in the RFCs, May have different behaviors. This is at least a SHOULD. But, for the specific car of JSON Literals, duplicate keys would violate the requirements of JCS. |
What I meant by "JSON subset" is the subset of YAML which is, effectively JSON. I.e., the arrays, objects and native values that both YAML and JSON share. Perhaps there is another term for this. The JSON-LD Internal Representation of a JSON Object is, however, an Infra map, which is defined specifically to have unique key/value pairs. All JSON-LD algorithms operate by transforming the JSON surface syntax into the internal representation, which will end up eliminating duplicate keys, in any case. |
iiuc:
Infra map: ordered sequence of key/value pairs. Keys are unique. Keys are strings. About orderingJSON libraries do not usually preserve ordering. I suspect that it is in general not a problem since iiuc
About YAML-LDIF JSON Literals are about Internal representation (the serialization always happens via JCS) then I think we do not need a We only need WDYT? |
This issue was discussed on the Aug 03 meeting. |
This comment was marked as resolved.
This comment was marked as resolved.
I took care of it. |
I propose closing this saying that YAML-LD has no specific encoding requirements for |
@gkellogg can you please check if this way of using https://github.com/ioggstream/draft-polli-restapi-ld-keywords/pull/3/files |
Yes, that seems reasonable. |
Uh, wouldn't YAML-LD provide thousands of such examples? I think we need to consider JSON and YAML literals completely independently of whether or not they have any relation to LD (just like
Let me try to adapt our first example https://graphdb.ontotext.com/documentation/10.0/lucene-graphdb-connector.html#using-the-create-command from Turtle+JSON to YAML-LD+YAML: '@context':
luc: http://www.ontotext.com/connectors/lucene#
luc-index: http://www.ontotext.com/connectors/lucene/instance#
ex: http://www.ontotext.com/example/wine#
rdfs: http://www.w3.org/2000/01/rdf-schema#
luc-index:my_index:
luc:createConnector: !yaml
types: [ex:Wine]
fields:
- fieldName: grape
propertyChain: [ex:madeFromGrape, rdfs:label]
- fieldName: sugar
propertyChain: [ex:hasSugar]
analyzed: false
multivalued: false
- fieldName: year
propertyChain: [ex:hasYear]
analyzed: false I think you'll agree that's much nicer than the original. So it's not a question of whether we need it, but how exactly to handle it:
Note: if we change our connector implementation to use RDF instead of JSON and add a bit to the context, this becomes straight YAML-LD (notice '@context':
luc: http://www.ontotext.com/connectors/lucene#
luc-index: http://www.ontotext.com/connectors/lucene/instance#
ex: http://www.ontotext.com/example/wine#
rdfs: http://www.w3.org/2000/01/rdf-schema#
fieldName: {'@id': luc:fieldName}
types: {'@id': luc:types, '@type': '@id', '@collection': '@list'}
fields: {'@id': luc:fields, '@type': '@id', '@collection': '@list'}
propertyChain: {'@id': luc:propertyChain, '@type': '@id', '@collection': '@list'}
analyzed: {'@id': luc:analyzed, '@type': xsd:boolean}
multivalued: {'@id': luc:multivalued, '@type': xsd:boolean}
luc-index:my_index:
luc:createConnector:
types: [ex:Wine]
fields:
- fieldName: grape
propertyChain: [ex:madeFromGrape, rdfs:label]
- fieldName: sugar
propertyChain: [ex:hasSugar]
analyzed: false
multivalued: false
- fieldName: year
propertyChain: [ex:hasYear]
analyzed: false This YAML-LD will be converted to the following turtle: luc-index:my_index
luc:createConnector [
luc:types (ex:Wine);
luc:fields (
[luc:fieldName "grape";
luc:propertyChain (ex:madeFromGrape rdfs:label)]
[luc:fieldName "sugar";
luc:propertyChain (ex:hasSugar);
luc:analyzed: false;
luc:multivalued: false]
[luc:fieldName "year";
luc:propertyChain (ex:hasYear);
luc:analyzed: false])] |
This comment was marked as resolved.
This comment was marked as resolved.
Done. |
This was discussed on [2022-09-28](https://json-ld.org/minutes/2022-09-28/#31)Vladimir Alexiev: I gave an example from Elastic Search. This connector can be used in indexing. ✪
... Fields have types and other attributes.
... Currently, we implement this in JSON. There's a SPARQL INSERT involved.
... We've wanted to turn that into a better notation, as you can't use prefixes.
... We're thinking of converting it to proper RDF; the question is how to write it.
... If we allow JSON and YAML literals, it would help with the interpretation of that data.
... If JSON was done because it was popular, it makes sense that you be able to store YAML as a literal.
... A good example is GeoJSON. In JSON-LD 1.1, it can be interpreted.
... But, it comes out as a nested list of lists.
... There are textual formats for GeoJSON.
... I think we should have a YAML literal.
Gregg Kellogg: There's the JCS spec to canonize a JSON literal. We don't have such a thing for YAML ✪
... the value of canonization is that then you can compare literals for equality, so that value equality will coincide with lexical equality
Vladimir Alexiev: Ok, I see but 1. RDF doesn't even canonize simple things like xsd:boolean, numbers (123 vs 0123), and even URLs ✪
... 2. We could tackle YAML canonization, in fact I'd like to have that (and standardize pretty-printing parameters, and the ability to capture them in YAML-LD)
Gregg Kellogg: Sorry, out of time for today. We can contniue on next call. Please send in discussion topics for next meeting agenda. ✪
Created json-ld/json-ld.org#797 -> action 797 create a repo for NDJSON-LD [1] (on ) due 5 Oct 2022 ✪
|
From the RDF Semantics
The JSON-LD 1.1 Spec defines this for the For a hypothetical YAML datatype, the lexical space would clearly be the set of all UNICODE strings which conform to the YAML Grammar, but finding the value space is more difficult,, as multiple YAML serializations may be considered to represent the same value. I think a necessary pre-condition for establishing a YAML datatype would be to identify a normative specification for obtaining the canonical form of a YAML document/stream. |
The YAML examples in the JSON-LD 1.1 spec (e.g., https://github.com/w3c/json-ld-syntax/blob/main/yaml/JSON-Literal-compacted.yaml), do not preserve the JSON serialization of a JSON literal.
It should, instead be the following:
But a simple
YAML.dump
of the parsed JSON does not take this into consideration. The spec should describe the requirements for serializing JSON literals in YAML-LD.The text was updated successfully, but these errors were encountered: