Home > Web Front-end > JS Tutorial > What are the Different Definitions of Valid JSON?

What are the Different Definitions of Valid JSON?

DDD
Release: 2024-11-06 22:50:02
Original
935 people have browsed it

What are the Different Definitions of Valid JSON?

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.

The above is the detailed content of What are the Different Definitions of Valid JSON?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template