zumalifeguard zumalifeguard - 5 months ago 11
JSON Question

Is this valid JSON? Does root of a JSON stream/file have to be a single object or array?

Is the following valid JSON?


["start", 1234]
["open", 97]


I read the official standard twice and I wasn't able to find anything that said that this isn't valid JSON.

Answer

Interesting question. Couldn't help but research a bit. RFC-7159 explicitly refers to ECMA-404, which says:

A JSON value can be an object, array, number, string, true, false, or null

So basically, ECMA-404 tells us that a JSON value can be either of the above, but only a single one of them. Given your example:

["start", 1234]
["open", 97]

That'd not be considered valid JSON together, at it is not an array, but two arrays, and therefore two JSON values and not one.