What's the difference between JSON.stringify and stringify-for-source?
JSON.stringify(obj) produces a JSON document — a string that another machine can JSON.parse. Stringify-for-source goes one step further: it wraps that JSON document in quotes and escapes the inner quotes, producing a string literal that can be pasted directly into JavaScript, Java, or Python source. So {"a":1} becomes "{\"a\":1}" — a literal string token your compiler will accept.
Why escape JSON?
Three common reasons. First, embedding sample JSON inside a unit test assertion (assert response == "..."). Second, storing a JSON payload as a string column in a database that does not have a native JSON type. Third, passing JSON through a system that only accepts strings — URL query params, environment variables, shell arguments, HTML data-* attributes. Each of these requires the JSON to be a single, escaped string token.
What characters get escaped?
The standard JSON escape sequences: double-quote (\"), backslash (\\), forward-slash (optionally \/), backspace (\b), form-feed (\f), newline (\n), carriage return (\r), tab (\t), and any control char or non-BMP code point as \uXXXX. The output matches what JSON.stringify produces in JavaScript and json.dumps produces in Python.
Can I reverse it — string back to JSON?
Yes. Switch the mode toggle to String → JSON, paste the escaped string (with the surrounding quotes), and the tool unescapes and re-formats it as pretty JSON. Useful for reading a JSON column you fetched from a database where the value is stored as an escaped string.
Why does my output have backslashes everywhere?
That is the point — it is a string literal. Every double-quote in your JSON is preceded by a backslash so the surrounding quotes don't terminate the string early. Paste the result between two quotes in your source file and the compiler will interpret the escapes back to a regular JSON string at runtime.
Does the output work in every language?
The escapes used (\", \\, \n, \t, \uXXXX) are accepted by JavaScript, TypeScript, Java, C#, Go, Rust, Python (with double-quoted strings), JSON itself, and most shell here-docs. Single-quoted Python strings and shell single-quoted strings have different rules — convert the surrounding quotes if you target those.
Will this work for embedding JSON in HTML?
For HTML data-* attributes or inline JSON-LD scripts, you also need to handle < (which can break script tags) and & (HTML entity start). The plain JSON escape produced by this tool is correct for JavaScript string embedding but for HTML you should additionally HTML-encode angle brackets and ampersands.
Is my JSON sent to a server?
No. Stringify and unescape both run entirely in your browser using JavaScript. JSON containing API keys, secrets, or proprietary payloads never leaves your device. Open DevTools Network tab and verify — no request fires when you click Convert.