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.