JSON in JavaScript

From the JavaScript cheat sheet · Objects & Arrays · verified Jul 2026

JSON

Parse and serialize data with JSON.parse() and JSON.stringify()

javascript
// Parse JSON string → object
const data = JSON.parse('{"name":"Alice","age":30}');

// Serialize object → JSON string
const json = JSON.stringify({ name: "Alice", age: 30 });
💡 JSON.stringify(obj, null, 2) pretty-prints with indentation — great for debugging
⚡ Use structuredClone() instead of JSON parse/stringify for deep cloning — handles Dates, Maps, Sets
📌 JSON cannot serialize undefined, functions, Symbols, or circular references
🟢 response.json() in fetch is a shorthand for JSON.parse(await response.text())
jsonparsestringify

More JavaScript tasks

Back to the full JavaScript cheat sheet