How to escape a JSON string
- Paste the text with Mode on Escape. The output updates as you type.
- Turn off Wrap in quotes to drop the outer
"when pasting into an existing string. - To go the other way, switch Mode to Unescape (below).
An HTML snippet with a tab after Code::
<p class="note">Hi {{name}},</p>
<p>Code: A-17 \ valid 24 h</p>
becomes:
"<p class=\"note\">Hi {{name}},</p>\n<p>Code:\tA-17 \\ valid 24 h</p>"
Double quotes become \", backslashes \\, line breaks \n and tabs \t. Other control characters become \u codes such as \u0007. Accented letters and emoji stay as they are: a JSON string can hold any Unicode character.
Unescape a string from a log
Paste a JSON string, with or without its outer quotes. Logs often hold JSON that was stringified twice:
"{\"event\":\"signup\",\"user\":{\"id\":42,\"plan\":\"trial\"}}"
Unescape returns the JSON inside, ready to indent in the JSON formatter:
{"event":"signup","user":{"id":42,"plan":"trial"}}
Invalid input gets a reason: C:\data\new fails with Invalid escape \d in a string., because \d is not a JSON escape (\n is, and would become a line break). Escaped first, the path becomes "C:\\data\\new".
Why JSON escaping matters
A raw line break inside a JSON string causes Bad control character in string literal, and an unescaped double quote ends the string early. More parse errors: common JSON errors. For Base64 rather than escaped text, use Base64 to JSON.