Skip to content
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

Pospone discussion on "$" and "@" #9

Closed
ioggstream opened this issue May 27, 2022 · 7 comments
Closed

Pospone discussion on "$" and "@" #9

ioggstream opened this issue May 27, 2022 · 7 comments
Milestone

Comments

@ioggstream
Copy link
Contributor

Proposal

JSON-LD is complex. YAML is very complex and - as the YAML community says - it's a live specification that is undergoing
continuous revisions. For example:

  • YAML 1.2 deprecated many 1.1 functionalities but some of them are still present in the current spec examples;
  • Some deprecated but "killer" features like merge keys <<: have not been replaced by new ones, so implementers still support them;
  • While YAML serialized using the flow collection styles can appear like JSON, YAML MUST not be considered a superset of JSON;
  • "@" in YAML is reserved for future use since forever, and this might change.

In this context, focusing on switching "@" with "$" to avoid quoting could lead to a dead end e.g. this is both valid in YAML and JSON, and it's just the first example that come to my mind

{
  "@context": {
    "@vocab": "https://www.w3.org/2019/wot/json-schema#",
    "title": { "@id": "dct:title", "@type": "xsd:string" },
    "description": { "@id": "dct:description", "@type": "xsd:string" },
    "$id": { "@id": "@id" },
    "type": { "@id": "@type" },
    "object": "ObjectSchema"
  },
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://example.com/product.schema.json",
  "title": "Product",
  "description": "A product in the catalog",
  "type": "object"
}

I'd focus on YAML structure

imho I would focus:

Once identified the relations with these specific YAML features, I think we will be ready tame things like tags (which are not very interoperable in the wild).

The ongoing work on YAML fragment identifiers could even provide further benefits since it can reference both JSON Paths and alias nodes.

My2¢,
R.

@anatoly-scherbakov
Copy link
Contributor

anatoly-scherbakov commented May 29, 2022

  • merge keys
  • alias nodes
  • cycles

Could you share any compelling use cases for these special features, to put them in context and to make it easier to understand them?

This is up to your convenience but I'd suggest creating a separate issue for each.

As to the title of this issue:

"@" in YAML is reserved for future use since forever, and this might change.

Exactly; that's also why we're not allowing @-keywords in YAML files. $ is not a reserved character, and therefore $-keywords are safer to use.

this is both valid in YAML and JSON

Yes, if a JSON-LD file author uses $ in the file then JSON-LD → YAML-LD → JSON-LD conversion will not yield a result identical to the original file. But does it matter?

The graphs resulting from each of these files will be identical. I propose to use that as the main criterion. Ultimately, the purpose of all these -LD formats is to convert something into an RDF graph, I would say.

It is also important to mention that JSON Schema $schema keyword will not be converted, it will stay as is because @schema is not a valid JSON-LD keyword.

I posted some additional thoughts at #11.

@ioggstream
Copy link
Contributor Author

that's also why we're not allowing @-keywords in YAML files

I meant that if the problem is quoting, we could discuss with YAML folks and ask them to unreserve @ in YAML 1.3.
The argument is that, since it's more than 10 years that that's reserved, it can be fair to "release" it.
At this point, there will be no reason for messing with that syntax.

@anatoly-scherbakov
Copy link
Contributor

I took the liberty to ask in the issue referenced above.

@VladimirAlexiev
Copy link
Contributor

@ioggstream Thanks for this important issue! In fact you discuss several important issues, I wish you opened them as separate issues rather than under this unsexy title "postpone discussion"

While YAML serialized using the flow collection styles can appear like JSON, YAML MUST not be considered a superset of JSON

Can you please elaborate on this? Is there any valid JSON that's invalid YAML?

Cannot this

    "$id": { "@id": "@id" },
    "type": { "@id": "@type" },

be written more simply as

    "$id": "@id" ,
    "type": "@type" ,

$ vs @

AFAIK, JS programmers dislike punctuation in field names because they like to write var.id instead of var["@id"].
Is it allowed to write var.$id? (@anatoly-scherbakov ?)
If not, is it ok to appropriate underscore and write var._id (@gkellogg what do you think?)

@ioggstream
Copy link
Contributor Author

Is there any valid JSON that's invalid YAML?

In YAML 1.2, all valid JSON parses to valid YAML. When discussing with YAML folks, they told me that this cannot be guaranteed for YAML 1.3 and that you should parse JSON with JSON parsers, and YAML with YAML parser.

about your examples

in yaml you cannot add "," at the end. I think it's ok.

about punctuation & co

Being a pythonista, I like punctuation. Still, my experience suggests to stay away from this kind of issues when you work on an existing language and you are not the sole implementor of parsers and serializers :)

@anatoly-scherbakov
Copy link
Contributor

Being a pythonista just like @ioggstream I am not very keen on Javascript but, after a brief test, it appears that var.$id is allowed in JS. @VladimirAlexiev

@VladimirAlexiev
Copy link
Contributor

Closing as agreed by @ioggstream: this has a lot of great discussion but it's unfocused, so relevant stuff needs to be posted as distinct issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants