Are JSON values valid JSON? Are JSON values valid JSON? json json

Are JSON values valid JSON?


As of March 2014: Yes. From the specification:

A JSON text is a serialized value. Note that certain previousspecifications of JSON constrained a JSON text to be an object or anarray. Implementations that generate only objects or arrays where aJSON text is called for will be interoperable in the sense that allimplementations will accept these as conforming JSON texts.

However, at the time this question was originally asked, the answer was: No. The original specification said:

A JSON text is a serialized object or array

So the outer-most data type in a JSON text had to be either an object or an array, it couldn't be a string, boolean, number or any other data type.


Yes, according to ECMA-404 The JSON Data Interchange Standard.

Source: http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-404.pdf

A JSON text is a sequence of tokens formed from Unicode code points that conforms to the JSON value grammar.

And following, the JSON value grammar is given as:

A JSON value can be an object, array, number, string, true, false, or null.

This directly conflicts with the RFC, as cited by @quentin. The updated RFC is 8259 which states:

Note that certain previous specifications of JSON constrained a JSON text to be an object or an array. Implementations that generate only objects or arrays where a JSON text is called for will be interoperable in the sense that all implementations will accept these as conforming JSON texts.