---
hide_title: false
hide_table_of_contents: false
pagination_next: null
pagination_prev: null
---
# JSON.parse()

The **`JSON.parse()`** method parses a JSON string, constructing the JavaScript value or object described by the string. An optional _reviver_ function can be provided to perform a transformation on the resulting object before it is returned.

## Syntax

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

### Parameters

- `text`
  - : The string to parse as JSON.
- `reviver` _**optional**_
  - : If a function, this prescribes how each value originally produced by parsing is transformed before being returned. Non-callable values are ignored. The function is called with the following arguments:
    - `key`
      - : The key associated with the value.
    - `value`
      - : The value produced by parsing.

### Return value

The `Object`, `Array`, string, number, boolean, or `null` value corresponding to the given JSON `text`.

### Exceptions

- [`SyntaxError`](../../globals/SyntaxError/SyntaxError.mdx)
  - : Thrown if the string to parse is not valid JSON.

## Description

`JSON.parse()` parses a JSON string according to the [JSON grammar](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/JSON#full_json_grammar), then evaluates the string as if it's a JavaScript expression. The only instance where a piece of JSON text represents a different value from the same JavaScript expression is when dealing with the `"__proto__"` key — see [Object literal syntax vs. JSON](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Operators/Object_initializer#object_literal_syntax_vs._json).

### The reviver parameter

If a `reviver` is specified, the value computed by parsing is _transformed_ before being returned. Specifically, the computed value and all its properties (in a [depth-first](https://en.wikipedia.org/wiki/Depth-first_search) fashion, beginning with the most nested properties and proceeding to the original value itself) are individually run through the `reviver`.

The `reviver` is called with the object containing the property being processed as `this`, and two arguments: `key` and `value`, representing the property name as a string (even for arrays) and the property value. If the `reviver` function returns [`undefined`](../../globals/undefined.mdx) (or returns no value — for example, if execution falls off the end of the function), the property is deleted from the object. Otherwise, the property is redefined to be the return value. If the `reviver` only transforms some values and not others, be certain to return all untransformed values as-is — otherwise, they will be deleted from the resulting object.

Similar to the `replacer` parameter of [`JSON.stringify()`](../../globals/JSON/stringify.mdx), `reviver` will be last called on the root object with an empty string as the `key` and the root object as the `value`. For JSON text parsing to primitive values, `reviver` will be called once.

Note that `reviver` is run after the value is parsed. So, for example, numbers in JSON text will have already been converted to JavaScript numbers, and may lose precision in the process. To transfer large numbers without loss of precision, serialize them as strings, and revive them to [BigInts](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/BigInt), or other appropriate arbitrary precision formats.
