JSON String Escape / Unescape
Escape text for a JSON string, or unescape a JSON string back to plain text.
Results are provided as is, for general information. Check anything important before relying on it. See the Terms of Use.
About this tool
A JSON string value can't contain a raw double quote, backslash, line break or other control character; each has to be written as an escape such as \", \\, \n or \u0009. Escape mode turns any text into a valid JSON string value, ready to paste between quotes in a config file, API payload or test fixture. Options add the surrounding quotes and write every non-ASCII character as \uXXXX for ASCII-only output. Unescape mode reverses it: paste a string copied from a log or JSON document, with or without its quotes, and read the original text. Invalid escapes, raw line breaks and unescaped quotes are reported with their position instead of being guessed at. Everything runs in your browser.
How it works
" → \" \ → \\ line break → \n tab → \t other control chars → \u00XX optional: é → \u00e9
A JSON string sits between double quotes, so a quote or backslash inside the text must be escaped, and so must control characters such as line breaks. Unescaping reverses each escape; anything JSON does not define is reported as an error.
| Question | Working | Answer |
|---|---|---|
| Escape: He said "hi" | each " → \" | He said \"hi\" |
| Escape “line 1” and “line 2” on two lines | line break → \n | line 1\nline 2 |
| Escape “é” as ASCII-only | U+00E9 → \u00e9 | \u00e9 |
| Unescape "caf\u00e9 \ud83d\ude00" | drop the quotes; join the surrogate pair | café 😀 |
When to use it
Questions
Which characters must be escaped in a JSON string?
Three groups: the double quote (\"), the backslash (\\) and the control characters U+0000 to U+001F, which include line breaks and tabs. Control characters have short forms for the common ones (\n, \r, \t, \b, \f) and \u00XX for the rest. Everything else, including accented letters and emoji, may appear unescaped.
Do I need to escape forward slashes?
No. JSON allows \/ as an escape for /, and unescape mode accepts it, but a plain / is valid too, so escape mode leaves slashes alone. Some encoders write \/ so that a string containing </script> can sit safely inside an HTML script block.
Why are emoji written as two \u escapes?
A \u escape holds four hex digits, so it can only name characters up to U+FFFF. Characters beyond that, such as most emoji, are written as a UTF-16 surrogate pair: 😀 becomes \ud83d\ude00. Unescape mode joins the pair back into one character. This only applies with the non-ASCII option on; by default emoji stay as they are.
Why does unescaping fail on my string?
The usual causes are a raw line break or tab that was never escaped, a double quote inside the string that wasn't written as \", or an escape JSON doesn't define, such as \x41 or \'. The error gives the character position so you can find it. If the string came from JavaScript source rather than JSON, it may use escapes JSON doesn't allow.
Is this the same as JSON.stringify?
Escape mode with surrounding quotes produces the same string as JSON.stringify applied to a string, so the result can be read back with JSON.parse. Without quotes it gives just the contents, for pasting between quotes you already have.