[ Web Proxy ]
URL:
Viewing: https://developer.mozilla.org/ko/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 7.

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

JSON.parse() JSON , JavaScript . , reviver , .

In this article

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

console.log(obj.count);
// Expected output: 42

console.log(obj.result);
// Expected output: true

js
    JSON.parse(text[, reviver])

text

JSON . JSON JSON .

reviver Optional

, .

JSON Object.

JSON SyntaxError.

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 . reviver this , () . reviver undefined , . .

reviver , . .

js
JSON.parse(
  '{"p": 5}',
  (key, value) =>
    typeof value === "number"
      ? value * 2 //  2
      : value, //  
);

// { p: 10 }

JSON.parse('{"1": 1, "2": 2, "3": {"4": 4, "5": {"6": 6}}}', (key, value) => {
  console.log(key); //   ,   ("")
  return value; //    
});

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

js
//   SyntaxError
JSON.parse("[1, 2, 3, 4, ]");
JSON.parse('{"foo" : 1, }');

Specification
ECMAScript 2027 LanguageSpecification
# sec-json.parse


Web Proxy Viewer  |  New URL  |  Original Page