zumalifeguard zumalifeguard - 1 year ago 69
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 Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download