is the initial value of the *"JSON"* property of the global object.
45 |
is an ordinary object.
46 |
contains two functions, `parse` and `stringify`,functions that are used to parse and construct JSON texts.
47 |
has a [[Prototype]] internal slot whose value is %Object.prototype%.
48 |
does not have a [[Construct]] internal method; it cannot be used as a constructor with the `new` operator.
49 |
does not have a [[Call]] internal method; it cannot be invoked as a function.
50 |
51 |
The JSON Data Interchange Format is defined in ECMA-404. The JSON interchange format used in this specification is exactly that described by ECMA-404. Conforming implementations of `JSON.parse` and `JSON.stringify` must support the exact interchange format described in the ECMA-404 specification without any deletions or extensions to the format.
52 |
53 |
54 |
55 |
JSON.isRawJSON ( _O_ )
56 |
This function performs the following steps when called:
57 |
58 | 1. If Type(_O_) is Object and _O_ has an [[IsRawJSON]] internal slot, return *true*.
59 | 1. Return *false*.
60 |
61 |
62 |
63 |
64 |
65 |
JSON.parse ( _text_ [ , _reviver_ ] )
66 |
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*.
67 |
The optional _reviver_ parameter is a function that takes two parameters, _key_ and _value_. It can filter and transform the results. It is called with each of the _key_/_value_ pairs produced by the parse,For each value produced by the parse, it is called with three arguments (the key, the value, and a context object containing [for unmodified primitive values] details of the corresponding Parse Node) and its return value is used instead of the original value. If it returns what it received, the structure is not modified. If it returns *undefined* then the property is deleted from the result.
68 |
69 | 1. Let _jsonString_ be ? ToString(_text_).
70 | 1. [id="step-json-parse-validate"] Parse StringToCodePoints(_jsonString_) as a JSON text as specified in ECMA-404. Throw a *SyntaxError* exception if it is not a valid JSON text as defined in that specification.
71 | 1. Let _scriptString_ be the string-concatenation of *"("*, _jsonString_, and *");"*.
72 | 1. [id="step-json-parse-parse"] Let _script_ be ParseText(StringToCodePoints(_scriptString_), |Script|).
73 | 1. NOTE: The early error rules defined in have special handling for the above invocation of ParseText.
74 | 1. Assert: _script_ is a Parse Node.
75 | 1. [id="step-json-parse-eval"] Let _completion_ be Completion(Evaluation of _script_).
76 | 1. NOTE: The PropertyDefinitionEvaluation semantics defined in have special handling for the above evaluation.
77 | 1. Let _unfiltered_ be _completion_.[[Value]].
78 | 1. [id="step-json-parse-assert-type"] Assert: _unfiltered_ is either a String, Number, Boolean, Null, or an Object that is defined by either an |ArrayLiteral| or an |ObjectLiteral|.
79 | 1. If IsCallable(_reviver_) is *true*, then
80 | 1. Let _root_ be OrdinaryObjectCreate(%Object.prototype%).
81 | 1. Let _rootName_ be the empty String.
82 | 1. Perform ! CreateDataPropertyOrThrow(_root_, _rootName_, _unfiltered_).
83 | 1. Let _snapshot_ be CreateJSONParseRecord(_script_, _rootName_, _unfiltered_).
84 | 1. Return ? InternalizeJSONProperty(_root_, _rootName_, _reviver_, _snapshot_).
85 | 1. Else,
86 | 1. Return _unfiltered_.
87 |
88 |
The *"length"* property of the `parse` function is *2*𝔽.
89 |
90 |
Valid JSON text is a subset of the ECMAScript |PrimaryExpression| syntax. Step verifies that _jsonString_ conforms to that subset, and step asserts that that parsing and evaluation returns a value of an appropriate type.
91 |
However, because behaves differently during `JSON.parse`, 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, which likewise does not apply during `JSON.parse`, means that not all texts accepted by `JSON.parse` are valid as a |PrimaryExpression|, despite matching the grammar.
92 |
93 |
94 |
95 |
96 |
JSON Parse Record
97 |
A JSON Parse Record is a Record value used to describe the initial state of a value parsed from JSON text.
98 |
JSON Parse Records have the fields listed in .
99 |
100 |
101 |
102 |
Field Name
103 |
Value
104 |
Meaning
105 |
106 |
107 |
[[ParseNode]]
108 |
a Parse Node
109 |
The context Parse Node.
110 |
111 |
112 |
[[Key]]
113 |
a property name
114 |
The property name with which [[Value]] is associated.
115 |
116 |
117 |
[[Value]]
118 |
an ECMAScript language value
119 |
The value produced by evaluation of [[ParseNode]].
120 |
121 |
122 |
[[Elements]]
123 |
a List of JSON Parse Records
124 |
JSON Parse Records corresponding with the elements of a [[Value]] that is an Array, in order. If [[Value]] is not an Array, the List will be empty.
125 |
126 |
127 |
[[Entries]]
128 |
a List of JSON Parse Records
129 |
JSON Parse Records corresponding with the entries of a [[Value]] that is a non-Array Object, in source order. If [[Value]] is not a non-Array Object, the List will be empty.
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 | CreateJSONParseRecord (
138 | _parseNode_: a Parse Node,
139 | _key_: a property name,
140 | _val_: an ECMAScript language value,
141 | ): a JSON Parse Record
142 |
143 |
144 |
description
145 |
It recursively combines a _parseNode_ parsed from JSON text and the _val_ produced by its evaluation.
146 |
147 |
148 | 1. Let _typedValNode_ be ShallowestContainedJSONValue of _parseNode_.
149 | 1. Assert: _typedValNode_ is not ~empty~.
150 | 1. Let _elements_ be a new empty List.
151 | 1. Let _entries_ be a new empty List.
152 | 1. If _val_ is an Object, then
153 | 1. Let _isArray_ be ! IsArray(_val_).
154 | 1. If _isArray_ is *true*, then
155 | 1. Assert: _typedValNode_ is an |ArrayLiteral| Parse Node.
156 | 1. Let _contentNodes_ be ArrayLiteralContentNodes of _typedValNode_.
157 | 1. Let _len_ be the number of elements in _contentNodes_.
158 | 1. Let _valLen_ be ! LengthOfArrayLike(_val_).
159 | 1. Assert: _valLen_ = _len_.
160 | 1. Let _I_ be 0.
161 | 1. Repeat, while _I_ < _len_,
162 | 1. Let _propName_ be ! ToString(𝔽(_I_)).
163 | 1. Let _elementParseRecord_ be CreateJSONParseRecord(_contentNodes_[_I_], _propName_, ! Get(_val_, _propName_)).
164 | 1. Append _elementParseRecord_ to _elements_.
165 | 1. Set _I_ to _I_ + 1.
166 | 1. Else,
167 | 1. Assert: _typedValNode_ is an |ObjectLiteral| Parse Node.
168 | 1. Let _propertyNodes_ be PropertyDefinitionNodes of _typedValNode_.
169 | 1. NOTE: Because _val_ was produced from JSON text and has not been modified, all of its property keys are Strings and will be exhaustively enumerated in source text order.
170 | 1. Let _keys_ be ! EnumerableOwnProperties(_val_, ~key~).
171 | 1. For each String _P_ of _keys_, do
172 | 1. NOTE: In the case of JSON text specifying multiple name/value pairs with the same name for a single object (such as {"a":"lost","a":"kept"}), the value for the corresponding property of the resulting ECMAScript object is specified by the last pair with that name.
173 | 1. Let _propertyDefinition_ be ~empty~.
174 | 1. For each Parse Node _propertyNode_ of _propertyNodes_, do
175 | 1. Let _propName_ be PropName of _propertyNode_.
176 | 1. If SameValue(_propName_, _P_) is *true*, set _propertyDefinition_ to _propertyNode_.
177 | 1. Assert: _propertyDefinition_ is PropertyDefinition : PropertyName `:` AssignmentExpression.
178 | 1. Let _propertyValueNode_ be the |AssignmentExpression| of _propertyDefinition_.
179 | 1. Let _entryParseRecord_ be CreateJSONParseRecord(_propertyValueNode_, _P_, ! Get(_val_, _P_)).
180 | 1. Append _entryParseRecord_ to _entries_.
181 | 1. Else,
182 | 1. Assert: _typedValNode_ is not an |ArrayLiteral| Parse Node and not an |ObjectLiteral| Parse Node.
183 | 1. Return the JSON Parse Record { [[ParseNode]]: _typedValNode_, [[Key]]: _key_, [[Value]]: _val_, [[Elements]]: _elements_, [[Entries]]: _entries_ }.
184 |
185 |
186 |
187 |
188 |
189 |
190 | InternalizeJSONProperty (
191 | _holder_: an Object,
192 | _name_: a String,
193 | _reviver_: a function object,
194 | _parseRecord_: either a JSON Parse Record or ~empty~,
195 | ): either a normal completion containing an ECMAScript language value or a throw completion
196 |
197 |
198 |
199 |
200 |
This algorithm intentionally does not throw an exception if either [[Delete]] or CreateDataProperty return *false*.
201 |
202 |
It performs the following steps when called:
203 |
204 | 1. Let _val_ be ? Get(_holder_, _name_).
205 | 1. Let _context_ be OrdinaryObjectCreate(%Object.prototype%).
206 | 1. If _parseRecord_ is a JSON Parse Record and SameValue(_parseRecord_.[[Value]], _val_) is *true*, then
207 | 1. If _val_ is not an Object, then
208 | 1. Let _parseNode_ be _parseRecord_.[[ParseNode]].
209 | 1. Assert: _parseNode_ is not an |ArrayLiteral| Parse Node and not an |ObjectLiteral| Parse Node.
210 | 1. Let _sourceText_ be the source text matched by _parseNode_.
211 | 1. Perform ! CreateDataPropertyOrThrow(_context_, *"source"*, CodePointsToString(_sourceText_)).
212 | 1. Let _elementRecords_ be _parseRecord_.[[Elements]].
213 | 1. Let _entryRecords_ be _parseRecord_.[[Entries]].
214 | 1. Else,
215 | 1. Let _elementRecords_ be a new empty List.
216 | 1. Let _entryRecords_ be a new empty List.
217 | 1. If _val_ is an Object, then
218 | 1. Let _isArray_ be ? IsArray(_val_).
219 | 1. If _isArray_ is *true*, then
220 | 1. Let _elementRecordsLen_ be the number of elements in _elementRecords_.
221 | 1. Let _len_ be ? LengthOfArrayLike(_val_).
222 | 1. Let _I_ be 0.
223 | 1. Repeat, while _I_ < _len_,
224 | 1. Let _prop_ be ! ToString(𝔽(_I_)).
225 | 1. If _I_ < _elementRecordsLen_, let _elementRecord_ be _elementRecords_[_I_]. Otherwise, let _elementRecord_ be ~empty~.
226 | 1. Let _newElement_ be ? InternalizeJSONProperty(_val_, _prop_, _reviver_, _elementRecord_).
227 | 1. If _newElement_ is *undefined*, then
228 | 1. Perform ? _val_.[[Delete]](_prop_).
229 | 1. Else,
230 | 1. Perform ? CreateDataProperty(_val_, _prop_, _newElement_).
231 | 1. Set _I_ to _I_ + 1.
232 | 1. Else,
233 | 1. Let _keys_ be ? EnumerableOwnProperties(_val_, ~key~).
234 | 1. For each String _P_ of _keys_, do
235 | 1. Let _entryRecord_ be the element of _entryRecords_ whose [[Key]] field is _P_. If there is no such element, let _entryRecord_ be ~empty~.
236 | 1. Let _newElement_ be ? InternalizeJSONProperty(_val_, _P_, _reviver_, _entryRecord_).
237 | 1. If _newElement_ is *undefined*, then
238 | 1. Perform ? _val_.[[Delete]](_P_).
239 | 1. Else,
240 | 1. Perform ? CreateDataProperty(_val_, _P_, _newElement_).
241 | 1. Return ? Call(_reviver_, _holder_, « _name_, _val_, _context_ »).
242 |
243 |
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.
244 |
245 |
In the case where there are duplicate name Strings within an object, lexically preceding values for the same key shall be overwritten.
246 |
247 |
248 |
249 |
250 |
251 |
252 | Static Semantics: ShallowestContainedJSONValue ( ): a Parse Node or ~empty~
253 |
254 |
255 |
description
256 |
It performs a breadth-first search of the parse tree rooted at the context node, and returns the first node that is an instance of a nonterminal corresponding to a JSON value, or ~empty~ if there is no such node.
257 |
258 |
259 | 1. Let _F_ be the active function object.
260 | 1. Assert: _F_ is a `JSON.parse` built-in function object (see JSON.parse).
261 | 1. Let _types_ be « |NullLiteral|, |BooleanLiteral|, |NumericLiteral|, |StringLiteral|, |ArrayLiteral|, |ObjectLiteral|, |UnaryExpression| ».
262 | 1. Let _unaryExpression_ be ~empty~.
263 | 1. Let _queue_ be « this Parse Node ».
264 | 1. Repeat, while _queue_ is not empty,
265 | 1. Let _candidate_ be the first element of _queue_.
266 | 1. Remove the first element from _queue_.
267 | 1. Let _queuedChildren_ be *false*.
268 | 1. For each nonterminal _type_ of _types_, do
269 | 1. If _candidate_ is an instance of _type_, then
270 | 1. NOTE: In the JSON grammar, a number token may represent a negative value. In ECMAScript, negation is represented as a unary operation.
271 | 1. If _type_ is |UnaryExpression|, then
272 | 1. Set _unaryExpression_ to _candidate_.
273 | 1. Else if _type_ is |NumericLiteral|, then
274 | 1. Assert: _candidate_ is contained within _unaryExpression_.
275 | 1. Return _unaryExpression_.
276 | 1. Else,
277 | 1. Return _candidate_.
278 | 1. If _queuedChildren_ is *false* and _candidate_ is an instance of a nonterminal and _candidate_ Contains _type_ is *true*, then
279 | 1. Let _children_ be a List containing each child node of _candidate_, in order.
280 | 1. Set _queue_ to the list-concatenation of _queue_ and _children_.
281 | 1. Set _queuedChildren_ to *true*.
282 | 1. Return ~empty~.
283 |
284 |
285 |
286 | It may make sense to generalize this operation and define Contains in terms of it rather than vice versa, but Contains is currently limited to a single target nonterminal and has specialized treatment for e.g. |ClassTail| descending into |ClassBody| exclusively to inspect computed names.
287 |
288 |
289 |
290 |
291 |
292 |
293 |
294 |
295 |
JSON.rawJSON ( _text_ )
296 |
The `rawJSON` function returns an object representing raw JSON text of a string, number, boolean, or null value.
297 |
298 | 1. Let _jsonString_ be ? ToString(_text_).
299 | 1. Throw a *SyntaxError* exception if _jsonString_ is the empty String, or if either the first or last code unit of _jsonString_ is any of 0x0009 (CHARACTER TABULATION), 0x000A (LINE FEED), 0x000D (CARRIAGE RETURN), or 0x0020 (SPACE).
300 | 1. Parse StringToCodePoints(_jsonString_) as a JSON text as specified in ECMA-404. Throw a *SyntaxError* exception if it is not a valid JSON text as defined in that specification, or if its outermost value is an object or array as defined in that specification.
301 | 1. Let _internalSlotsList_ be « [[IsRawJSON]] ».
302 | 1. Let _obj_ be OrdinaryObjectCreate(*null*, _internalSlotsList_).
303 | 1. Perform ! CreateDataPropertyOrThrow(_obj_, *"rawJSON"*, _jsonString_).
304 | 1. Perform ! SetIntegrityLevel(_obj_, ~frozen~).
305 | 1. Return _obj_.
306 |
307 |
308 |
309 |
310 |
311 |
The `stringify` function returns a String in UTF-16 encoded JSON format representing an ECMAScript language value, or *undefined*. It can take three parameters. The _value_ parameter is an ECMAScript language value, which is usually an object or array, although it can also be a String, Boolean, Number or *null*. The optional _replacer_ parameter is either a function that alters the way objects and arrays are stringified, or an array of Strings and Numbers that acts as an inclusion list for selecting the object properties that will be stringified. The optional _space_ parameter is a String or Number that allows the result to have white space injected into it to improve human readability.
313 |
314 |
315 |
316 | SerializeJSONProperty (
317 | _state_: a JSON Serialization Record,
318 | _key_: a String,
319 | _holder_: an Object,
320 | ): either a normal completion containing either *undefined* or a String, or a throw completion
321 |
322 |
323 |
324 |
325 | 1. Let _value_ be ? Get(_holder_, _key_).
326 | 1. If _value_ is an Object or _value_ is a BigInt, then
327 | 1. Let _toJSON_ be ? GetV(_value_, *"toJSON"*).
328 | 1. If IsCallable(_toJSON_) is *true*, then
329 | 1. Set _value_ to ? Call(_toJSON_, _value_, « _key_ »).
330 | 1. If _state_.[[ReplacerFunction]] is not *undefined*, then
331 | 1. Set _value_ to ? Call(_state_.[[ReplacerFunction]], _holder_, « _key_, _value_ »).
332 | 1. If _value_ is an Object, then
333 | 1. If _value_ has an [[IsRawJSON]] internal slot, then
334 | 1. Return ! Get(_value_, *"rawJSON"*).
335 | 1. If _value_ has a [[NumberData]] internal slot, then
336 | 1. Set _value_ to ? ToNumber(_value_).
337 | 1. Else if _value_ has a [[StringData]] internal slot, then
338 | 1. Set _value_ to ? ToString(_value_).
339 | 1. Else if _value_ has a [[BooleanData]] internal slot, then
340 | 1. Set _value_ to _value_.[[BooleanData]].
341 | 1. Else if _value_ has a [[BigIntData]] internal slot, then
342 | 1. Set _value_ to _value_.[[BigIntData]].
343 | 1. If _value_ is *null*, return *"null"*.
344 | 1. If _value_ is *true*, return *"true"*.
345 | 1. If _value_ is *false*, return *"false"*.
346 | 1. If _value_ is a String, return QuoteJSONString(_value_).
347 | 1. If _value_ is a Number, then
348 | 1. If _value_ is finite, return ! ToString(_value_).
349 | 1. Return *"null"*.
350 | 1. If _value_ is a BigInt, throw a *TypeError* exception.
351 | 1. If _value_ is an Object and IsCallable(_value_) is *false*, then
352 | 1. Let _isArray_ be ? IsArray(_value_).
353 | 1. If _isArray_ is *true*, return ? SerializeJSONArray(_state_, _value_).
354 | 1. Return ? SerializeJSONObject(_state_, _value_).
355 | 1. Return *undefined*.
356 |
357 |
358 |
359 |
360 |
361 |
362 |
363 |
364 | Static Semantics: ArrayLiteralContentNodes (
365 | ): a List of Parse Nodes
366 |
367 |
368 |
369 |
370 |
371 | ArrayLiteral :
372 | `[` Elision? `]`
373 | `[` ElementList `]`
374 | `[` ElementList `,` Elision? `]`
375 |
376 |
377 | 1. Let _elements_ be a new empty List.
378 | 1. If |ElementList| is present, set _elements_ to the list-concatenation of _elements_ and ArrayLiteralContentNodes of |ElementList|.
379 | 1. If |Elision| is present, append |Elision| to _elements_.
380 | 1. Return _elements_.
381 |
382 |
383 | ElementList : Elision? AssignmentExpression
384 |
385 | 1. Let _elements_ be a new empty List.
386 | 1. If |Elision| is present, append |Elision| to _elements_.
387 | 1. Return the list-concatenation of _elements_ and « |AssignmentExpression| ».
388 |
389 |
390 | ElementList : Elision? SpreadElement
391 |
392 | 1. Let _elements_ be a new empty List.
393 | 1. If |Elision| is present, append |Elision| to _elements_.
394 | 1. Return the list-concatenation of _elements_ and « |SpreadElement| ».
395 |
396 |
397 | ElementList : ElementList `,` Elision? AssignmentExpression
398 |
399 | 1. Let _elements_ be ArrayLiteralContentNodes of |ElementList|.
400 | 1. If |Elision| is present, append |Elision| to _elements_.
401 | 1. Return the list-concatenation of _elements_ and « |AssignmentExpression| ».
402 |
403 |
404 | ElementList : ElementList `,` Elision? SpreadElement
405 |
406 | 1. Let _elements_ be ArrayLiteralContentNodes of |ElementList|.
407 | 1. If |Elision| is present, append |Elision| to _elements_.
408 | 1. Return the list-concatenation of _elements_ and « |SpreadElement| ».
409 |
410 |
411 |
412 |
413 |
414 |
415 |
416 | Static Semantics: PropertyDefinitionNodes (
417 | ): a List of Parse Nodes
418 |
does not have a [[Construct]] internal method; it cannot be used as a constructor with the new operator.
2565 |
does not have a [[Call]] internal method; it cannot be invoked as a function.
2566 |
2567 |
The JSON Data Interchange Format is defined in ECMA-404. The JSON interchange format used in this specification is exactly that described by ECMA-404. Conforming implementations of JSON.parse and JSON.stringify must support the exact interchange format described in the ECMA-404 specification without any deletions or extensions to the format.
2568 |
2569 |
2570 |
2571 |
1.1 JSON.isRawJSON ( O )
2572 |
This function performs the following steps when called:
2573 |
If Type(O) is Object and O has an [[IsRawJSON]] internal slot, return true.
Return false.
2574 |
2575 |
2576 |
2577 |
2578 |
1.2 JSON.parse ( text [ , reviver ] )
2579 |
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.
2580 |
The optional reviver parameter is a function that takes two parameters, key and value. It can filter and transform the results. It is called with each of the key/value pairs produced by the parse,For each value produced by the parse, it is called with three arguments (the key, the value, and a context object containing [for unmodified primitive values] details of the corresponding Parse Node) and its return value is used instead of the original value. If it returns what it received, the structure is not modified. If it returns undefined then the property is deleted from the result.
Parse StringToCodePoints(jsonString) as a JSON text as specified in ECMA-404. Throw a SyntaxError exception if it is not a valid JSON text as defined in that specification.
The "length" property of the parse function is 2𝔽.
2583 | Note
2584 |
Valid JSON text is a subset of the ECMAScript PrimaryExpression syntax. Step 2 verifies that jsonString conforms to that subset, and step 10 asserts that that parsing and evaluation returns a value of an appropriate type.
2585 |
However, because 13.2.5.5 behaves differently during JSON.parse, 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, which likewise does not apply during JSON.parse, means that not all texts accepted by JSON.parse are valid as a PrimaryExpression, despite matching the grammar.
2586 |
2587 |
2588 |
2589 |
2590 |
1.2.1 JSON Parse Record
2591 |
A JSON Parse Record is a Record value used to describe the initial state of a value parsed from JSON text.
2592 |
JSON Parse Records have the fields listed in Table 1.
JSON Parse Records corresponding with the entries of a [[Value]] that is a non-Array Object, in source order. If [[Value]] is not a non-Array Object, the List will be empty.
2624 |
2625 |
2626 |
2627 |
2628 |
2629 |
2630 |
1.2.2 CreateJSONParseRecord ( parseNode, key, val )
2631 |
The abstract operation CreateJSONParseRecord takes arguments parseNode (a Parse Node), key (a property name), and val (an ECMAScript language value) and returns a JSON Parse Record. It recursively combines a parseNode parsed from JSON text and the val produced by its evaluation. It performs the following steps when called:
NOTE: Because val was produced from JSON text and has not been modified, all of its property keys are Strings and will be exhaustively enumerated in source text order.
NOTE: In the case of JSON text specifying multiple name/value pairs with the same name for a single object (such as {"a":"lost","a":"kept"}), the value for the corresponding property of the resulting ECMAScript object is specified by the last pair with that name.
Let propertyDefinition be empty.
For each Parse NodepropertyNode of propertyNodes, do
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.
2652 | Note 2
2653 |
In the case where there are duplicate name Strings within an object, lexically preceding values for the same key shall be overwritten.
The syntax-directed operation ShallowestContainedJSONValue takes no arguments and returns a Parse Node or empty. It performs a breadth-first search of the parse tree rooted at the context node, and returns the first node that is an instance of a nonterminal corresponding to a JSON value, or empty if there is no such node.
2664 | It may make sense to generalize this operation and define Contains in terms of it rather than vice versa, but Contains is currently limited to a single target nonterminal and has specialized treatment for e.g. ClassTail descending into ClassBody exclusively to inspect computed names.
2665 |
2666 |
2667 |
2668 |
2669 |
2670 |
2671 |
2672 |
2673 |
1.3 JSON.rawJSON ( text )
2674 |
The rawJSON function returns an object representing raw JSON text of a string, number, boolean, or null value.
Throw a SyntaxError exception if jsonString is the empty String, or if either the first or last code unit of jsonString is any of 0x0009 (CHARACTER TABULATION), 0x000A (LINE FEED), 0x000D (CARRIAGE RETURN), or 0x0020 (SPACE).
Parse StringToCodePoints(jsonString) as a JSON text as specified in ECMA-404. Throw a SyntaxError exception if it is not a valid JSON text as defined in that specification, or if its outermost value is an object or array as defined in that specification.
1.4 JSON.stringify ( value [ , replacer [ , space ] ] )
2681 |
The stringify function returns a String in UTF-16 encoded JSON format representing an ECMAScript language value, or undefined. It can take three parameters. The value parameter is an ECMAScript language value, which is usually an object or array, although it can also be a String, Boolean, Number or null. The optional replacer parameter is either a function that alters the way objects and arrays are stringified, or an array of Strings and Numbers that acts as an inclusion list for selecting the object properties that will be stringified. The optional space parameter is a String or Number that allows the result to have white space injected into it to improve human readability.
The abstract operation SerializeJSONProperty takes arguments state (a JSON Serialization Record), key (a String), and holder (an Object) and returns either a normal completion containing either undefined or a String, or a throw completion. It performs the following steps when called:
The syntax-directed operation ArrayLiteralContentNodes takes no arguments and returns a List of Parse Nodes. It is defined piecewise over the following productions:
The syntax-directed operation PropertyDefinitionNodes takes no arguments and returns a List of Parse Nodes. 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.
2797 |
2798 |
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
2799 |
2800 |
2801 |
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
2802 |
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.
2803 |
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.
2804 |
2805 |
2806 |
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.