Home > Article > Web Front-end > What Defines Valid JSON: RFC 4627 vs. ECMA-404?
The definition of JSON's syntax has been subject to subtle variations over time, leading to confusion regarding the precise criteria for valid JSON strings.
Initially, JSON's specification, as defined in RFC 4627, strictly limited valid JSON to serialized objects ({}) and arrays([]). This meant that simple values like strings, numbers, true, and false were not considered valid JSON on their own.
However, the introduction of ECMA-404 expanded the definition of JSON to include top-level JSONValues, which encompass all JSON data types. As a result, web browsers now allow all JSON values as valid JSON.
It's important to note that browsers implement the JSON object based on ES5, which allows scalar types and NULL as valid JSON values. This is an exception from the original RFC 4627 specification. Consequently, some other implementations, such as Ruby, adhere strictly to RFC 4627, resulting in different interpretations of valid JSON.
Understanding these nuances is crucial, especially when working with different JSON parsers and encoders. It's essential to confirm whether the implementation strictly follows RFC 4627 or adopts the more permissive ECMA-404 definition, as this affects the validation of JSON strings.
The above is the detailed content of What Defines Valid JSON: RFC 4627 vs. ECMA-404?. For more information, please follow other related articles on the PHP Chinese website!