Yes, an array is legal as top-level JSON-text.
There are four standard documents defining JSON: RFC 4627, RFC 7159 (which obsoletes RFC 4627), ECMA-404, and RFC 8259 (which obsoletes RFC 7159, and calls ECMA-404 normative). They differ in which top-level elements they allow, but all allow an object or an array as the top-level element.
Yes, but you should consider making the root an object instead in some scenarios, due to JSON hijacking. This is an information disclosure vulnerability based on overriding the array constructor in JavaScript.
This is from the ECMAScript specification.
JSONText : JSONValue JSONValue : JSONNullLiteral JSONBooleanLiteral JSONObject JSONArray JSONString JSONNumber
Yes you can do it. Put in [{}]
There is some confusion, seen in the other comments. The "application/json" media type allows only object or array at the top-level for JSON-text, per JSON RFC. However, for a parser any JSON value is acceptable, as seen in the ECMAScript specification.
Update: RFC 4627 is outdated. The new RFC permits also simple values at the top-level. (Thanks, Matthias Dieter Wallnöfer.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With