Is null valid JSON (4 bytes, nothing else)

Json

Json Problem Overview


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?

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?

Json Solutions


Solution 1 - Json

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.

Solution 2 - Json

[Note! This answer is no longer correct, see answer by @niksnut.]

Yes, both statements must be true. The literal token null is a JSON value. A JSON text is a serialized object or array, which requires {} or [].

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionRobert AltmanView Question on Stackoverflow
Solution 1 - JsonniksnutView Answer on Stackoverflow
Solution 2 - JsonRussell BorogoveView Answer on Stackoverflow