Understanding the Minimal Valid JSON
The concept of JSON has been widely discussed in various RFCs and specifications. RFC4627 initially defined JSON as being either a serialized object or array. Based on this definition, only {} (empty object) and [] (empty array) qualify as valid, complete JSON strings.
However, ECMA-404 introduced an amendment that expanded the range of valid JSON strings. With this update, string, number, true, false, null, {} (empty object), and [] (empty array) are all considered valid JSON strings.
In the realm of web browsers, JSON is standardized in ES5. ES5 defines valid JSON texts as the same as RFC 4627 with two exceptions. Firstly, the top-level JSONText production may consist of any JSONValue (including strings, numbers, booleans, and null) instead of being restricted to an object or array. This means that all JSON values are accepted in web browsers, even though the underlying JSON object may adhere to RFC 4627.
It's important to note that different parsers may have varying levels of support for the full range of valid JSON strings. For instance, Ruby only accepts objects and arrays as the root, while PHP expressly includes scalar types and NULL in its encoding and decoding capabilities.
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3