archives

« Bugzilla Issues Index

#2374 — Define a data model


ECMA-404 would be a better basis on which to build higher-level specifications, if it defined a relatively abstract, low-level data model.

This would define the least restrictive reasonable semantics: the semantics should not treat as identical any values that higher layers might reasonably want to treat as distinct. This would not claim to be the one, true JSON semantics: it would merely a semantic layer on which other higher-level semantic layers can conveniently be built.

I would suggest the following strawman

1. a JSON value is an object value, an array value, a number value, a string value, a boolean value or a null value.
2. an object value is an ordered sequence of <string, value> pairs
3. an array value is an ordered sequence of values
4. a number value is a rational number x/(10^n), where n is a non-negative integer, and x is an integer, and is not a multiple of 10 unless n is 0
5. a string value is an ordered sequence of Unicode code points

In terms of conformance, I would suggest the spec should say that a conforming parser must interpret JSON texts that represent the same JSON value identically. It should not require that a conforming parser expose this low-level data model.


Syntactically a JSON object looks like "an ordered sequence of <string, value> pairs". However, in practice the *data model* used in the vast majority of implementations for a JSON object is: a collection of <name, value> pairs, where order does not matter, and each name is a unique string.

Attempting to expand the object data model to allow duplicates and make order significant can only dilute the great interoperability JSON enjoys. Saying a message is JSON would no longer be sufficient to know that practically any JSON library can handle it.

The specification could add a paragraph noting that the syntax could be useful when element order matters or duplicates are allowed, but any such use of the syntax must not be labelled "JSON" as it will not be interoperable with many JSON-compliant systems.