JSON Stringify — Escape JSON for Code
Take a JSON document and produce an escaped single-line string ready to paste into JavaScript, Python, Go, Java source, or a shell command. Pick the target language for correct escaping; toggle Copy with var = to wrap as const data = "...";. Reverse mode turns an escaped string back into the original JSON.
How to stringify JSON
- Paste your JSON.
- Pick the Target language — JavaScript / JSON, Python, Go, Java, Shell single-quoted, Shell double-quoted. Each handles escapes differently.
- The output is the escaped string ready to assign to a variable. Copy copies just the string; Copy with var = wraps it as
const data = "...";(or the equivalent for the language). - Use Reverse to go back — turn an escaped string into the original JSON.
When to use which target
- JS / JSON: standard
\",\\\\,\\nescaping — also valid JSON. - Python: identical to JSON for ASCII;
json.loads(s)round-trips. - Go: Go's source-level string literal — same escapes as JS for printable ASCII.
- Java: same as Go for ASCII.
- Shell single-quoted: wraps in
'...'with embedded single quotes escaped via'\\''. Use forjqfilters and curl bodies. - Shell double-quoted: wraps in
"...", escapes$, backtick,\\,". Use only when you need variable interpolation.
FAQ
Why is the JS output the same as Python's?
For printable ASCII content they're identical. Differences only show with control characters, lone surrogates, or non-ASCII when you opt for \\u escapes.
Should I prefer single or double-quoted shell?
Single-quoted unless you actually need variable interpolation — single quotes prevent the shell from expanding $, backticks, and !, which is almost always what you want.
What does Reverse do?
It expects an escaped JSON string (one already wrapped in "..." or not) and decodes the escapes back to the original characters. If the result is itself JSON, it's pretty-printed.
Will it work offline?
Yes.