Variables, Types, and Collections23% of the exam

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.

Official exam objective
Given a JSON response, demonstrate how to operate the JSON object.

~5 min read · 10 practice questions ·

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

JSON property names
Detail
Double-quoted strings only; no trailing commas
Invalid JSON text
Detail
JSON.parse() throws SyntaxError
Reviver returns undefined
Detail
That property is deleted (the root too)
undefined/function in an object
Detail
Omitted
undefined/function in an array
Detail
Becomes null
NaN, Infinity
Detail
Serialized as null
Date
Detail
ISO string from toJSON()
BigInt or circular reference
Detail
TypeError
Replacer array
Detail
Allowlist of property names
Replacer function first call
Detail
Key "", value = the root object
space argument
Detail
Indentation only; capped at 10
Sources for this section (4)
  • 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))`?

The questions are free to read. Answers with their sources and self-grading are included with the pack.

Keep reading with the JavaScript Developer pack

  • Core concepts
  • Exam traps
  • Worked scenario

The pack includes:

  • All 24 lessons of the JavaScript Developer guide, with reading progress
  • Interactive decision walks and step-by-step sequence steppers
  • Inline practice questions and one-click topic practice (10 questions for this lesson)
  • An official source cited for every claim
  • An AI tutor that answers from the guide
  • Unlimited timed practice exams

Practice for the JavaScript Developer exam