JSON parsing


JSON.parse ()

The JSON.parse () method transfers the JSON cable, creating the JavaScript value or object defined by the cable. Optional rescue work can be provided to make changes to the resulting item before it is returned.

const json = '{"result": true, "count": 42}';
const obj = JSON.parse (json);
icon.log (obj.count);
// expected result: 42
icon.log (obj.result);
// expected exit: true

Syntax

JSON.parse (text)

JSON.parse (text, update)

Parameters

text
Scanning thread as JSON. See the JSON item for a description of the JSON syntax.
reviver Optional
If functionality, this means how the value originally generated by the analysis is converted, prior to recovery.
Return value
Object, Array, string, number, boolean, or null value corresponding to the given JSON text.

The opposite

Throws a SyntaxError variant if the browser thread does not work JSON.

The reviver parameter is used In the case of a refund, the estimated value of the refund is changed before the refund. Specifically, the combined value and all of its properties (starting with the most nested areas and moving on to the actual value) are shipped separately in return. After that it is called, the object of the asset is processed as follows, with the name of the property as a unit of letters, and the value of the property as arguments. If the reviver function returns undefined (or returns the value, for example, if the transaction decreases at the end of the transaction), the asset is removed from the item. Otherwise, the asset is reclassified as a recoverable amount.