This function parses a JSON text (a JSON-formatted String) and produces an ECMAScript language value. The JSON format represents literals, arrays, and objects with a syntax similar to the syntax for ECMAScript literals, Array Initializers, and Object Initializers. After parsing, JSON objects are realized as ECMAScript objects. JSON arrays are realized as ECMAScript Array instances. JSON strings, numbers, booleans, and null are realized as ECMAScript Strings, Numbers, Booleans, and null.
The optional reviver parameter is either a function that can filter and transform the results, or an options bag configuring native transforms. FWhen reviver is a function, for each value produced by the parse, reviver is called with three arguments (the associated property key, the value, and a context object). If the property is unmodified and its value is primitive, the provided context object has a "source" property containing source text of the corresponding Parse Node. If the call returns undefined, the property is deleted. Otherwise, the property is redefined to use the return value.
If jsonParseNode is not a Parse Node, throw a SyntaxError exception.
Let key be the empty String.
Let result be the JSONEvaluation of jsonParseNode with arguments key and options.
Return result.
It is not permitted for a conforming implementation of JSON.parse to extend the JSON grammars. If an implementation wishes to support a modified or extended JSON interchange format it must do so by defining a different parse function.
Note 2
Valid JSON text is a syntactic subset of the ECMAScript PrimaryExpression syntax. However, because JSONEvaluation behaves differently than Evaluation, the same source text can produce different results when evaluated as a PrimaryExpression rather than as JSON. Furthermore, the early error for duplicate "__proto__" properties in object literals (13.2.5.1), which has no analogue in JSON, means that some texts accepted by ParseJSON are not valid as a PrimaryExpression, (e.g., {"__proto__":null,"__proto__":null}).
Note 3
In the case where there are duplicate name Strings within an object, lexically preceding values for the same key shall be overwritten.
1.1.1.2 JSON Parse Options Records
A JSON Parse Options Record is a Record value used to specify JSON deserialization options.
JSON Parse Options Records have the fields listed in Table 1.
It generally produces the same values as Evaluation given the same inputs, but is defined over a much narrower set of productions, namely ECMA-404's JSONValue. Unlike Evaluation, it does not raise an early error when "__proto__" appears twice as a key (see 13.2.5.1). It also does not perform [[SetPrototypeOf]] when encountering a "__proto__" key, and instead creates an ordinary data property (see 13.2.5.5).
It is defined piecewise over the following productions:
If options.[[Freeze]] is true, perform ! SetIntegrityLevel(obj, frozen).
Return the JSON Parse Record { [[ParseNode]]: JSONObject, [[Key]]: key, [[Value]]: obj, [[Elements]]: « », [[Entries]]: entries }.
1.1.1.5 Runtime Semantics: JSONArrayAccumulation
The syntax-directed operation JSONArrayAccumulation takes arguments array (an Array), options (a JSON Parse Options Record), elements (a List of JSON Parse Records), and nextIndex (a non-negative integer) and returns a non-negative integer. It is analagous to ArrayAccumulation, except defined over a much narrower grammar (namely ECMA-404), and calls JSONEvaluation on its elements, rather than Evaluation. It is defined piecewise over the following productions:
The syntax-directed operation JSONMemberListEvaluation takes arguments obj (an Object), options (a JSON Parse Options Record), and entries (a List of JSON Parse Records) and returns unused. It is analagous to PropertyDefinitionEvaluation, except 1) it is defined over a much narrower grammar, 2) it does not include the special handling of "__proto__" described in 1.1.1.4, and 3) it calls JSONEvaluation instead of Evaluation. It is defined piecewise over the following productions:
All Software contained in this document ("Software") is protected by copyright and is being made available under the "BSD License", included below. This Software may be subject to third party rights (rights from parties other than Ecma International), including patent rights, and no licenses under such third party rights are granted under this license even if the third party concerned is a member of Ecma International. SEE THE ECMA CODE OF CONDUCT IN PATENT MATTERS AVAILABLE AT https://ecma-international.org/memento/codeofconduct.htm FOR INFORMATION REGARDING THE LICENSING OF PATENT CLAIMS THAT ARE REQUIRED TO IMPLEMENT ECMA INTERNATIONAL STANDARDS.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
Neither the name of the authors nor Ecma International may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE ECMA INTERNATIONAL "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ECMA INTERNATIONAL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.