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

rdf:JSON equality simplification? #103

Open
iherman opened this issue Oct 21, 2024 · 7 comments
Open

rdf:JSON equality simplification? #103

iherman opened this issue Oct 21, 2024 · 7 comments
Assignees
Labels
needs discussion Proposed for discussion in an upcoming meeting spec:enhancement Issue or proposed change to enhance the spec without changing the normative content substantively

Comments

@iherman
Copy link
Member

iherman commented Oct 21, 2024

A question: in other specifications, we use the RFC 8785 (JSON Canonicalization Scheme (JCS)) reference for normative text. Wouldn't it be possible to make the value space description on the equality simply say that two JSON strings are equal iff their Canonical versions should be identical? (There might be some issues with datatypes, I am not sure.)

B.t.w., minor editorial glitch: In A.3 The rdf:JSON Datatype the note on the value space has the "and" rendered as a code. It probably should not.

@iherman iherman added the spec:enhancement Issue or proposed change to enhance the spec without changing the normative content substantively label Oct 21, 2024
@gkellogg
Copy link
Member

There have been some discussions on if JCS is appropriate for this purpose. Given that the value space is now objects, and not strings, going to a JCS string representation would require the objects to be converted back to a string, and would not be as useful when comparing native JSON values, such as numbers and booleans.

I note your markup concern, which I'll handle along with other editorial note you've made. (Thanks!)

@gkellogg gkellogg self-assigned this Oct 21, 2024
@iherman
Copy link
Member Author

iherman commented Oct 22, 2024

Given that the value space is now objects, and not strings, going to a JCS string representation would require the objects to be converted back to a string, and would not be as useful when comparing native JSON values, such as numbers and booleans.

Just for the sake of arguments: actually, at least in JavaScript, doing a

jcs(JSON.stringify(a)) === jcs(JSON.stringify(b))

is a widely used idiom to compare two objects. (In fact, the JCS implementations usually accept an object argument and produce a canonical JSON string representation of the object).

But, if this was discussed, I have no reason to object the WG's resolution, so it is all right to close the issue.

@afs
Copy link
Contributor

afs commented Oct 22, 2024

jcs(JSON.stringify(a)) === jcs(JSON.stringify(b))

That would work as an implementation.

@iherman
Copy link
Member Author

iherman commented Oct 22, 2024

jcs(JSON.stringify(a)) === jcs(JSON.stringify(b))

That would work as an implementation.

Yes, and that is indeed a Javascript implementation, may not be valid for other languages; the mapping from a, say, RUST object to JSON may be more complicated. Although... the RDF spec refers to the INFRA standard, whose mapping to JSON is standardized, so that definition may also work for rdf:JSON's specification as well after all.

However. The whole issue comes from the definition of the rdf:JSON datatype. Why not making it simpler and say that the value space of the datatype is the set of canonical JSON strings? The lexical-to-value space mapping is JCS itself, and equality is simple. RDF does not need to standardize the object equivalent of a JSON string; i.e., from an RDF point of view strings as value space could work all right.

JCS is an IETF RFC (RFC 8785), has been used in other Rec-track documents at W3C (e.g., ECDSA cryptosuite) and it saves us the time and energy it takes to complicate the RDF 1.2 specification.) Why reinvent the wheel?

(I know I am late in the game...)

@gkellogg
Copy link
Member

The original proposal was to use the JCS version of the JSON Literal as the value space, as was done in JSON-LD. But, this met with resistance, and having the value space be based on INFRA datatypes, along with xsd:double, is useful for those that actually want the value to be useful as native components.

We also considered using JCS for equality, vs. the current description of equality which is recursive on maps and arrays and leans on XSD notions of equality for numbers. I'm not opposed to this, and it would also be useful for ordering purposes.

@gkellogg gkellogg added the needs discussion Proposed for discussion in an upcoming meeting label Oct 22, 2024
@afs
Copy link
Contributor

afs commented Oct 22, 2024

Yes, and that is indeed a Javascript implementation, may not be valid for other languages

In Java, structures like map and list define "equals" to be structural equality - "same elements".

@pfps
Copy link
Contributor

pfps commented Oct 24, 2024

JCS only handles JSON that maps into non-infinite IEEE floating point numbers as far as I can tell, i.e., it does not handle 1E400, which is currently allowed in rdf:JSON. 1E400 is also allowed in xsd:double and maps to +INF.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs discussion Proposed for discussion in an upcoming meeting spec:enhancement Issue or proposed change to enhance the spec without changing the normative content substantively
Projects
None yet
Development

No branches or pull requests

4 participants