JSON Stringify: Escape and Unescape JSON Strings
Turn text or a JSON document into an escaped JSON string literal, exactly what JSON.stringify(text) returns, for embedding JSON inside JSON, environment variables, or source code. Or paste an escaped literal and unwrap it, layer by layer. Optional JavaScript, Python, Java, C#, Go, and shell output. Everything runs in your browser.
Options
Used only when the input is parsed as JSON.
Results update as you type. Ctrl+Enter or Cmd+Enter converts immediately.
Copy and Download use the exact result, including characters a text box cannot display.
Ready.
Where the problem is
Warnings
Layers unwrapped
Diagnostics
How it works and limits
Stringify wraps the text in double quotes and escapes ", \, and U+0000 to U+001F (as \b \f \n \r \t or \u00XX), matching JSON.stringify and RFC 8259. The tool uses its own encoder so it can add options, then checks the result with your browser's JSON.parse. Double stringify applies plain JSON.stringify first, then your options to the outer layer.
Parse as JSON first validates the input and re-indents it token by token. Numbers, key order, duplicate keys, and string escapes stay exactly as written. A real JSON.parse then JSON.stringify round trip would round integers above 253 and move integer-like keys first. Warnings flag these cases.
Lone surrogates are UTF-16 halves (U+D800 to U+DFFF) without a partner, often left behind when an emoji is cut in half. They cannot be encoded as UTF-8. Since ES2019, well-formed JSON.stringify writes them as \udXXX escapes instead of raw invalid text, and this tool does the same. Python, Java, C#, and JavaScript strings can hold them, so their output keeps the escape. Go forbids surrogate escapes, and shell text is UTF-8 bytes, so those outputs use U+FFFD and show a warning. Go's own encoding/json makes the same replacement.
Language output encodes the same value as the JSON literal. JavaScript always escapes U+2028 and U+2029 for engines older than ES2019. Python writes characters above U+FFFF as \UXXXXXXXX, because \uD83D\uDE00 would be two separate surrogates in Python. Java uses octal escapes for control characters, because \u000a becomes a real line break before the compiler reads the string. C# never uses its variable-length \x escape. Shell output is for sh, bash, and zsh single quotes, where nothing is escaped and each ' becomes '\''. A shell string cannot contain NUL.
Unstringify decodes strictly by RFC 8259 and reports the line and column of the first bad escape, raw control character, or missing quote. \x41, \', and octal escapes are errors in JSON. Unwrapping repeats while the result is another JSON string, up to 64 layers, then pretty-prints the result if it is a JSON value.
Limits. Browsers turn CRLF line breaks typed or pasted into a text box into LF. Use Load file to keep CR characters exactly. The round-trip check for Python, Java, C#, Go, and shell decodes the output with this tool's model of each language's escape rules, not with the real compiler. JSON5, comments, and single-quoted strings are not accepted. Very large inputs, several megabytes or more, may feel slow. Nothing is stored or sent anywhere.