Favorites

JavaScript JSON.parse() Method

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
JSON.parse()
JavaScript JSON Static methodThis method is supported by all modern browsers.
Updated 28th November 2026

The JSON.parse() static method reads a string of JSON text and turns it into the JavaScript value it describes, such as an object or array.

Description

The JSON.parse() static method parses a JSON string and returns the JavaScript value it describes. It is how you read JSON received from a server, from localStorage or from a file.

JSON syntax is stricter than JavaScript: keys and strings must use double quotes, and trailing commas and comments are not allowed. Invalid input throws a SyntaxError, so wrap calls on untrusted data in try...catch.

The optional reviver function lets you transform values as they are parsed, for example to turn date strings back into Date objects. When working with fetch(), the response's json() method parses the body for you.

Syntax

JSON.parse(text)
JSON.parse(text, reviver)

Parameters

  • textThe string to parse as JSON.
  • reviverOptional. A function called for each key and value, which can change a value before it is returned.

Return Value

The object, array, string, number, boolean or null that the JSON text represents.

Exceptions

  • SyntaxErrorThrown if the string is not valid JSON.

Example

const data = JSON.parse('{"name":"Sam","scores":[10,20]}');
console.log(data.name, data.scores);

try {
  JSON.parse("{name: 'Sam'}");   // not valid JSON
} catch (err) {
  console.error(err.name);
}

const withDate = JSON.parse('{"when":"2026-11-28"}', (key, value) =>
  key === 'when' ? new Date(value) : value);
console.log(withDate.when instanceof Date);

Browser Support

The following information will show you the current browser support for the JSON.parse() method. Hover over a browser icon to see the version that first introduced support for this method.

This method is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee