JSON Stringify / Unstringify
Escape a JSON object into a single quoted string literal for embedding in code, or unescape a stringified JSON string back to readable JSON.
1,005 views
How It Works
Stringify takes real JSON and escapes it into a single-line, quote-escaped string literal — the form you need when embedding JSON inside another JSON field, a config value, or a source-code string constant. Internally this is exactly what JavaScript's JSON.stringify() does: it walks the value, quotes strings, escapes control characters and embedded quotes, and serializes objects and arrays into text. Unstringify reverses it: paste an escaped JSON string (with \" and \n) and get back clean, readable, indented JSON, equivalent to calling JSON.parse() on it and pretty-printing the result.
Concrete example: the object {"name":"Ada","tags":["a","b"]} stringifies to the literal "{\"name\":\"Ada\",\"tags\":[\"a\",\"b\"]}" — every inner double quote gets a backslash in front of it so the whole thing can live inside one outer pair of quotes. This is exactly what happens when an API wraps a JSON payload as a string inside another JSON response (a webhook body, a log line, a database column typed as text), or when a JSON value has to be dropped into a YAML file, an environment variable, or a string constant in source code without breaking the surrounding syntax. Unstringify does the reverse: paste that escaped blob and get back the original, indented and readable.
A few behaviors of JSON.stringify() are worth knowing even if you never touch this exact tool: undefined values and functions are silently dropped from object properties (a key holding undefined simply disappears), but the same values inside an array are converted to null instead of being dropped, since arrays must keep their length and index positions intact. Date objects are not serialized as objects — they are converted through their toJSON() method into an ISO 8601 string like "2024-01-15T10:30:00.000Z". And a value that contains a circular reference — an object that (directly or through a chain of properties) refers back to itself — cannot be stringified at all: real JSON.stringify() throws a TypeError: Converting circular structure to JSON, because there is no finite string that could represent an infinitely nested structure.
What You Should Know
Stringifying is a lossy operation in one specific sense: whatever gets silently dropped (functions, undefined properties, Symbol keys) cannot be recovered by unstringifying afterward — the round trip only preserves what valid JSON can represent in the first place, which is strings, numbers, booleans, null, plain objects and arrays. In real code, JSON.stringify() also accepts two extra arguments beyond the value itself: a replacer (a function or array of key names controlling exactly which properties get included, or how their values are transformed before serializing), and a space parameter (a number or string that turns the compact single-line output into indented, human-readable JSON — this is precisely the difference between a minified API response and the pretty-printed version a debugger shows you).
Double-encoded JSON is a common source of confusion: if a value looks like a JSON string but its very first character is a quote mark and it is full of backslash-escaped inner quotes, it has likely been stringified twice — once by the application, once again by a layer that did not realize the payload was already a JSON string. Running it through unstringify once resolves the outer layer; if the result still looks escaped, run it again.
Frequently Asked Questions
What is the difference from JSON.stringify in code?
The same operation, just as an interactive tool: paste real JSON, get the escaped string form you would otherwise write JSON.stringify(obj) to produce — useful when you do not have a console handy.
Why would I need to unstringify JSON?
APIs and logs sometimes nest a JSON string inside a JSON field (double-encoded JSON) — unstringify converts that inner escaped string back into readable, parseable JSON.
Why did a property disappear after stringifying?
JSON.stringify() silently omits object properties whose value is undefined or a function — there is no JSON representation for either, so the key is dropped entirely rather than serialized as null. The same undefined value inside an array becomes null instead of vanishing, since arrays must preserve their length and index order.
Why do I get a "circular structure" error?
If an object references itself, directly or through a chain of other objects, JSON.stringify() cannot produce a finite string for it and throws a TypeError. This is common when serializing objects that hold a back-reference to their parent (a child node pointing back to its tree, a DOM element, a class instance with a "self" field) — the fix is to strip or replace the circular property before serializing, often with a replacer function.
Is my data uploaded?
No — both directions run locally in your browser.
Similar Tools
Report a Problem
JSON Stringify / Unstringify
Comments
No comments yet — be the first to write one!