JSON.stringify vs JSON.parse โ Differences Explained
Published: July 25, 2025 ยท Last updated: September 7, 2026 ยท 6 min read ยท By JSON Suite Team
These two functions are the core of JSON handling in JavaScript. They work in opposite directions, and understanding them fully โ including their quirks โ will save you from hard-to-debug bugs. For a deeper dive into JSON parsing, see our complete JavaScript JSON parsing guide.
The One-Line Summary
| Function | Direction | Returns |
|---|---|---|
JSON.parse(str) | JSON string โ JS value | Object, array, string, number, boolean, or null |
JSON.stringify(val) | JS value โ JSON string | String |
JSON.parse() in Depth
Signature: JSON.parse(text, reviver?)
JSON.stringify() in Depth
Signature: JSON.stringify(value, replacer?, space?)
What JSON.stringify Silently Drops
This is the most common source of bugs. These JavaScript values are not representable in JSON:
Key rule: If a value would serialize as undefined, it gets dropped entirely when it's an object property. If it's in an array, it becomes null.
toJSON() โ Custom Serialization
You can control how any object is serialized by adding a toJSON() method. JSON.stringify calls it automatically.
Circular Reference Error
Trying to stringify an object that references itself throws a TypeError.
Solutions: use a replacer function to detect and skip circular refs, or use a library like flatted or json-stringify-safe for serializing circular structures.
Quick Reference
| Use Case | Use This |
|---|---|
| Parse API response body | JSON.parse(text) or response.json() |
| Send data in fetch body | JSON.stringify(data) |
| Save to localStorage | localStorage.setItem(key, JSON.stringify(val)) |
| Read from localStorage | JSON.parse(localStorage.getItem(key)) |
| Deep clone (simple objects) | JSON.parse(JSON.stringify(obj)) |
| Pretty-print for debugging | JSON.stringify(obj, null, 2) |
| Filter sensitive fields | JSON.stringify(obj, ["field1","field2"]) |
Learn More
For complete coverage of JSON in JavaScript, check our comprehensive JavaScript JSON guide. Watch out for common JSON errors when parsing external data. If you're working with Python, see our Python JSON parsing guide. For fundamentals, start with what is JSON.
Try Our JSON Tools
- JSON Formatter โ equivalent to JSON.stringify(data, null, 2) in your browser
- Fix JSON โ repair malformed JSON that causes JSON.parse() to throw
- JSON Tree Viewer โ explore any JSON structure visually
Related Tools
Work with JSON.stringify and JSON.parse using these tools:
- JSON Formatter โ pretty-print JSON like JSON.stringify
- Fix JSON โ repair broken JSON before parsing
- JSON Tree Viewer โ visualize parsed JSON structures
- JSON Compare โ compare stringified outputs