Did the publication of ECMA-404 affect the validity of JSON texts such as ‘2’ or ‘”hello”‘?

Douglas Crockford posted a comment on this Google+ post which helped me start to clarify things:

JSON is just a grammar, and the grammar includes numbers and strings. Uses of JSON must necessarily be more restrictive. RFC-4627 is one possible use, and was never intended to be the standard for JSON itself.

We cannot say that non-array non-object JSON texts are generally invalid, just that it is not valid to use them with internet media type application/json, per RFC-4627.

Representations of non-object non-array values are valid JSON texts per ECMA-404, which is the only currently published standard that might be identified as “the JSON specification”.

However, it turns out that the IETF is likely to soon publish a replacement to RFC-4627 which will also be a specification of JSON. Its latest draft still includes the restriction on JSON texts, but also mentions that JSON has be specified in several places and that these specifications vary slightly. The draft specifically mentions that the definition of JSON in ECMA-262 (the ECMAScript/JavaScript specification) does not share the top-level value restriction.

Therefore, the question of whether non-object non-arrays are valid JSON texts must be disambiguated:

Is "hello" a valid JSON text as specified in RFC-4627 and its successor?

No.

Is "hello" a valid JSON text as specified by ECMA-404 and ECMA-262?

Yes.

Leave a Comment