Skip to content

Chapter 18 of 33

JSON

Parse, validate, transform, stringify, and safely exchange JSON-compatible data.

30 minutes 10 quick checksBy Subha Prasad
Lesson 18 of 33Course navigation

Lesson content

Read, practise, then check your understanding

JSON represents objects, arrays, strings, finite numbers, booleans, and null. It has no undefined, BigInt, functions, symbols, comments, dates, references, or cyclic graphs.

Controlled conversion

const value = JSON.parse(text, (key, item) =>
  key.endsWith("At") ? new Date(item) : item
);
const output = JSON.stringify(value, ["id", "name"], 2);

Parsing proves syntax, not application validity—validate shapes, sizes, ranges, and allowed keys. Revivers transform bottom-up; replacers select/transform output. Dates normally become strings and BigInt throws unless explicitly converted. Never evaluate JSON as code and place limits on untrusted payload depth and size.

Knowledge check

Answer every question correctly to complete this chapter.

Which statement best describes JSON?
Which JavaScript term matches this description: A text data format supporting objects, arrays, strings, numbers, booleans, and null.
Which statement best describes JSON.parse?
Which JavaScript term matches this description: Conversion from JSON text to JavaScript values.
Which statement best describes JSON.stringify?
Which JavaScript term matches this description: Conversion from supported JavaScript data to JSON text.
Which statement best describes reviver?
Which JavaScript term matches this description: A parse callback transforming reconstructed values.
Which statement best describes replacer?
Which JavaScript term matches this description: A stringify callback or property list selecting/translating output.

0 of 10 checks passed

Your progress is saved on this device.