# JSON parse and stringify

*JavaScript Developer Study Guide · Variables, Types, and Collections · Last updated October 16, 2026 · https://www.certifyforce.com/study-guide/javascript-developer/variables-types-and-collections/json-parse-and-stringify*

Turning JSON text into objects and back: strict JSON syntax, navigating nested response data, the JSON.parse reviver, what JSON.stringify drops or converts (undefined, functions, Date, Map, NaN), replacer arrays and functions, indentation, toJSON, and the limits of a JSON round-trip deep copy.

- Certification: Salesforce JavaScript Developer
- Exam section: Variables, Types, and Collections
- Study guide: https://www.certifyforce.com/study-guide/javascript-developer

**Official exam objective:**

> Given a JSON response, demonstrate how to operate the JSON object.

## What the exam expects

- Recognise valid JSON text and predict when `JSON.parse()` throws `SyntaxError`.
- Parse a response and read nested values with dot, bracket and array-index access, iterating arrays with `for...of` or array methods.
- Transform values while parsing with a reviver (for example, ISO strings to `Date`).
- Predict `JSON.stringify()` output for `undefined`, functions, `null`, `NaN`, `Date`, `Map`, `Set` and objects with `toJSON()`.
- Filter or reshape output with a replacer array or function, and indent it with the `space` argument.
- Explain what a `JSON.parse(JSON.stringify(x))` copy loses.
- Key terms: **JSON text** (a string in JSON syntax, not an object); **parse** (text → JavaScript value); **serialize/stringify** (value → JSON text); **reviver** (a `parse` callback that can replace each value); **replacer** (a `stringify` array or callback that selects or replaces values).

## Key facts

| Fact | Detail | Source |
|---|---|---|
| JSON property names | Double-quoted strings only; no trailing commas | [JSON](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON) |
| Invalid JSON text | `JSON.parse()` throws `SyntaxError` | [JSON.parse()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse) |
| Reviver returns `undefined` | That property is deleted (the root too) | [JSON.parse()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse) |
| `undefined`/function in an object | Omitted | [JSON.stringify()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify) |
| `undefined`/function in an array | Becomes `null` | [JSON.stringify()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify) |
| `NaN`, `Infinity` | Serialized as `null` | [JSON.stringify()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify) |
| `Date` | ISO string from `toJSON()` | [Date.prototype.toJSON()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toJSON) |
| `Map`, `Set` | `{}` | [JSON.stringify()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify) |
| BigInt or circular reference | `TypeError` | [JSON.stringify()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify) |
| Replacer array | Allowlist of property names | [JSON.stringify()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify) |
| Replacer function first call | Key `""`, value = the root object | [JSON.stringify()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify) |
| `space` argument | Indentation only; capped at 10 | [JSON.stringify()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify) |

## Check yourself

- Why does `JSON.parse("{'a': 1}")` throw?
- When should you use a reviver instead of post-processing?
- What does `JSON.stringify({ tags: ['a', undefined], note: undefined })` return?
- Why does a replacer function that returns `undefined` for every key except `password` give `undefined`?
- What type is a `Date` property after `JSON.parse(JSON.stringify(obj))`?

## Sources

- [JSON](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON)
- [Working with JSON](https://developer.mozilla.org/en-US/docs/Learn_web_development/Core/Scripting/JSON)
- [JSON.parse()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse)
- [JSON.stringify()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify)
- [Date.prototype.toJSON()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toJSON)
- [Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)
- [for...of](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...of)
- [for...in](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...in)
- [Optional chaining (?.)](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Optional_chaining)
- [Map](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map)

## About the full unit

The "Core concepts", "Exam traps" and "Worked scenario" sections of this unit, its 10 linked practice questions, and unlimited timed mock exams are included with the JavaScript Developer pack (USD $19): https://www.certifyforce.com/practice-exams
