[ Web Proxy ]
URL:
Viewing: https://developer.mozilla.org/ru/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse [Back]  [Original]

JSON.parse() - JavaScript | MDN

This page was translated from English by the community. Learn more and join the MDN Web Docs community.

View in English Always switch to English

JSON.parse()

Baseline
Widely available
*

This feature is well established and works across many devices and browser versions. Its been available across browsers since 2015 ..

* Some parts of this feature may have varying levels of support.

JSON.parse() JSON, .

In this article

JSON.parse(text[, reviver])

text

JSON. JSON JSON.

reviver

, , , .

Object, JSON text.

SyntaxError, JSON.

: JSON.parse()

js
JSON.parse("{}"); // {}
JSON.parse("true"); // true
JSON.parse('"foo"'); // "foo"
JSON.parse('[1, 5, "false"]'); // [1, 5, "false"]
JSON.parse("null"); // null

: reviver

reviver, , , . , ( ), reviver, this, , : . reviver undefined ( , , ), . .

, reviver , . , JSON.parse() undefined.

js
JSON.parse('{"p": 5}', function (k, v) {
  if (k === "") {
    return v;
  } //    -  
  return v * 2; //   v * 2.
}); // { p: 10 }

JSON.parse('{"1": 1, "2": 2, "3": {"4": 4, "5": {"6": 6}}}', function (k, v) {
  console.log(k); //    ,    ""
  return v; //    
});

// 1
// 2
// 4
// 6
// 5
// 3
// ""

Specification
ECMAScript 2027 LanguageSpecification
# sec-json.parse


Web Proxy Viewer  |  New URL  |  Original Page