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.
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()throwsSyntaxError. - Parse a response and read nested values with dot, bracket and array-index access, iterating arrays with
for...ofor array methods. - Transform values while parsing with a reviver (for example, ISO strings to
Date). - Predict
JSON.stringify()output forundefined, functions,null,NaN,Date,Map,Setand objects withtoJSON(). - Filter or reshape output with a replacer array or function, and indent it with the
spaceargument. - 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
parsecallback that can replace each value); replacer (astringifyarray 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()throwsSyntaxError
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()
Map, Set- Detail
{}
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
- 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