| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/zh-TW/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse | [Back] [Original] |
Get to know MDN better
This feature is well established and works across many devices and browser versions. Its been available across browsers since 20157.
* Some parts of this feature may have varying levels of support.
JSON.parse() JSON JavaScript reviver
JSON.parse(text[, reviver])
JSON text Object
JSON SyntaxError
JSON.parse()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 reviver undefined
reviver
JSON.parse('{"p": 5}', function (k, v) {
if (typeof v === "number") {
return v * 2; // return v * 2 for numbers
}
return v; // return everything else unchanged
});
// { p: 10 }
JSON.parse('{"1": 1, "2": 2, "3": {"4": 4, "5": {"6": 6}}}', function (k, v) {
console.log(k); // log the current property name, the last is "".
return v; // return the unchanged property value.
});
// 1
// 2
// 4
// 6
// 5
// 3
// ""
JSON.parse() // SyntaxError
JSON.parse("[1, 2, 3, 4, ]");
JSON.parse('{"foo" : 1, }');
| Specification |
|---|
| ECMAScript 2027 LanguageSpecification # sec-json.parse |
Gecko 29 JSON JSON
JSON.parse("[1, 2, 3, 4,]");
// SyntaxError: JSON.parse: unexpected character at
// line 1 column 13 of the JSON data
This page was last modified on 2025714 by MDN contributors.
Your blueprint for a better internet.
Portions of this content are 19982026 by individual mozilla.org contributors. Content available under a Creative Commons license.
| Web Proxy Viewer | New URL | Original Page |