JSON Escape / Unescape

Escape strings for safe embedding in JSON, or decode escaped JSON back to its raw form. Quotes, backslashes, control chars, Unicode.

MODE
RAW INPUTplain text
ESCAPED OUTPUT
// escaped string appears here

When you actually need this

Three patterns come up over and over. First, embedding a JSON payload inside another JSON document — for example, a log entry whose "body" field contains the request body. The inner JSON has to be escaped or the outer parse fails.

Second, storing JSON in a SQL string column where you cannot use the database's native JSON type. Third, putting JSON in an HTML data- attribute, an environment variable, or a YAML string — anywhere the surrounding format reserves quotes and backslashes.

For all of these the rule is the same: backslash becomes two backslashes, double-quote becomes backslash-quote, newlines and tabs become their two-character escapes.

Escape mode

Turns raw text into a JSON-safe escaped string. Optionally wrap the result in double quotes to make it a valid JSON string literal, or force ASCII-only output with \uXXXX escapes for the safest possible serialisation.

Unescape mode

Reverses the escaping, decoding \n, \t, \", \\, and \uXXXX sequences. Tolerates input with or without surrounding quotes — paste either way.

Common questions

When do I need to escape JSON?
Whenever you embed a JSON string inside another string: storing JSON in a database TEXT column with single-quote SQL escaping, putting JSON inside an HTML data- attribute, sending JSON as a JWT claim, logging JSON safely so newlines do not break log parsers, or building a JSON string literal inside another JSON document.
What characters get escaped?
Per RFC 8259: the backslash \\ becomes \\\\, the double quote " becomes \\", and control characters (newline, tab, carriage return, backspace, form feed) become their two-character escape sequences \\n, \\t, \\r, \\b, \\f. Unicode characters above U+007F are left as-is (a valid choice per the spec).
What is the difference between escape and stringify?
JSON.stringify on a string wraps it in quotes AND escapes the content. This tool offers both modes. "Escape" is what you want when embedding a string in source code; "stringify" (escape + wrap quotes) is what you want when embedding the result back into another JSON document.
Does this handle Unicode correctly?
Yes. Characters above U+007F are passed through unchanged by default (a valid JSON), which keeps the output readable and smaller. If you need ASCII-only output, use the \\uXXXX escape mode in the toggle below the input.
Why does my escaped string still break?
Most common cause: the string was already partially escaped. If your input is "He said \\\"hi\\\"" and you escape again, you end up with double-escaped backslashes. Inspect the raw input character by character if you suspect mixed escaping.
Is my data private?
Yes. Everything runs locally — no upload, no log, no analytics on the text content.