Are JSON values string, number, true, false, null valid JSON? I.e., is
true
a valid JSON document? Or does is have to be an array/object?
Some validators accept this (e.g. http://jsonlint.com/), while others do not (e.g. http://jsonschemalint.com/). The RFC and json.org are not clear on this issue.
It is a common mistake to call a JSON object literal "a JSON object". JSON cannot be an object. JSON is a string format. The data is only JSON when it is in a string format.
A valid JSON object which is a list of key:value pairs separated by commas and enclosed between a left brace and right brace. A valid JSON value that is not a JSON array or a JSON object. A scalar value can be a character string, a number, or one of the JSON literals: null , true , or false .
undefined , Function , and Symbol values are not valid JSON values.
As of March 2014: Yes. From the specification:
A JSON text is a serialized value. 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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With