JSON.parse / JSON.stringify basics
Convert objects to JSON strings and back; use replacer/reviver briefly; handle bad input safely.
Why JSON?
Goal: Serialize and parse safely.
- JSON.stringify → string
- JSON.parse ← string
- replacer/reviver (taste)
- Basic safety tips

stringify()
Use JSON.stringify(value) to get a JSON string. For readability, pass a space number (e.g., 2).
// Turn a value into a JSON string
const user = { name: "Ayla", score: 12, active: true };
const json = JSON.stringify(user);
console.log("json:", json);
// Optional: pretty-print with spaces (2)
const pretty = JSON.stringify(user, null, 2);
console.log("pretty:", pretty);

All lessons in this course
- JSON.parse / JSON.stringify basics
- Structured cloning & URLSearchParams
- Safe JSON parsing strategies