0

Among the implementations listed at JSON.org I stumbled upon JSON_checker.

It's copyrighted by JSON.org (which is why I call it "official") and it seems to be very up-to-date: 2016-10-24 is stamped at the top of JSON_checker.c.

However, I noticed that state transition table (line 143 in JSON_checker.c) defines the starting state (called GO) such that it only allow:

  • Whitespace
  • Start of an object ({)
  • Start of an array ([)

What about the other "primitive" value types: String, Number, Boolean, Null?

There is indeed a state (called VA for value) that do allow these primitives as well as Objects and Arrays. But why isn't that the initial starting state?

For example; a simple JSON document containing just:

null

Is not considered valid according to the JSON_checker.

It is apparent that this is by design; the first test (fail1.json) in the test suite clearly states that:

"A JSON payload should be an object or array, not a string."

Why is this so? My previous experience with JSON is that any JSON value is allowed at the top level.

Mårten Wikström
  • 11,074
  • 5
  • 47
  • 87
  • Because...Crockford. Just about everyone else is happy with any kind of top-level value, and that's what [was standardized](http://www.ecma-international.org/publications/standards/Ecma-404.htm). – T.J. Crowder Nov 01 '16 at 11:36
  • Ok, that's very... confusing. Nevertheless, your comment answer my question. Post it as an answer so that I can accept it. – Mårten Wikström Nov 01 '16 at 11:41

0 Answers0