Skip to content
UniCircle
EasyConceptualBasics

JSON and serialisation

Question JS-JSN-001

What is JSON? How do JSON.stringify and JSON.parse work, and which JavaScript values do not survive a round trip?

Show the explanation

Model answer. JSON (JavaScript Object Notation) is a text format for data: objects, arrays, strings, numbers, booleans and null. Keys must be double-quoted strings; there are no comments, functions, undefined or trailing commas. It is language-independent, which is why APIs use it.

  • JSON.stringify(value, replacer?, indent?) turns a value into a JSON string (serialisation).
  • JSON.parse(text, reviver?) turns JSON text back into values (deserialisation); invalid text throws a SyntaxError, so wrap untrusted input in try/catch.
JavaScript
const s = JSON.stringify({ id: 7, tags: ['a'], when: new Date(0), skip: undefined });
// '{"id":7,"tags":["a"],"when":"1970-01-01T00:00:00.000Z"}'
JSON.parse(s).when;   // a string now, not a Date

Values that change or disappear: undefined, functions and symbols are dropped (or become null in arrays); Date becomes a string; NaN and Infinity become null; Map and Set become {}; BigInt throws; circular references throw.

Original UniCircle question. Last reviewed 22 Oct 2026.