Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is null valid JSON (4 bytes, nothing else)

Tags:

json

Hot debate today:

Is the text stream null valid JSON?

According to http://www.ietf.org/rfc/rfc4627.txt?number=4627:

...
2. JSON Grammar

A JSON text is a sequence of tokens. The set of tokens includes six structural characters, strings, numbers, and three literal names.

A JSON text is a serialized object or array.

Should this interpreted as both statements must be true in order for the text to be valid JSON?

  • http://code.google.com/p/json-framework/issues/detail?id=49 seems to indicate (at the bottom) that this is invalid.
  • http://json.parser.online.fr/ also flags this as invalid.

However, many other libraries seem to permit it, and indeed, it seems like a single valid token could be a legitimate result.

Is there a definitive answer?

like image 783
Robert Altman Avatar asked Dec 15 '11 21:12

Robert Altman


People also ask

Is null in JSON valid?

When serializing to JSON, if a value of a property in the data object is null, then it will be serialized as a JSON null.

How do I check if a JSON is null?

To check null in JavaScript, use triple equals operator(===) or Object is() method. If you want to use Object.is() method then you two arguments. 1) Pass your variable value with a null value. 2) The null value itself.

Can a JSON key be null?

JSON has two types of null value In JSON there are effectively two types of null . When the key is provided, and the value is explicitly stated as null . When the key is not provided, and the value is implicitly null .

Does JSON use none or null?

JSON has a NULL data type, but it has not a None data type. A dictionary in Python cannot have null as a value but can have “null” as a value that can be interpreted as a string.


1 Answers

RFC 7159 drops the limitation that a JSON text must be an object or an array. The grammar specifies:

JSON-text = ws value ws

where

value = false / null / true / object / array / number / string

Thus, "null" is now a valid JSON document.

like image 113
niksnut Avatar answered Sep 21 '22 08:09

niksnut