Skip to content

JSON Escape & Unescape

This JSON escape tool turns text into a valid JSON string and unescapes logged strings back into plain text.

Input · Text
Output · JSON string
Valid TextRuns in your browser

Load from a URL

Your browser fetches it directly, so the server must allow cross-origin requests (CORS).

How to escape a JSON string

  1. Paste the text with Mode on Escape. The output updates as you type.
  2. Turn off Wrap in quotes to drop the outer " when pasting into an existing string.
  3. 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.

Questions

How do I get the same result in code?

JavaScript JSON.stringify(text) gives exactly this output, quotes included. Python matches it with json.dumps(text, ensure_ascii=False); without that flag it writes non-ASCII characters as \u codes.

Why does Unescape reject a backslash before a single quote?

That is not a JSON escape. JSON strings use double quotes, so a single quote needs no escaping; remove the backslash.

Is the text saved or uploaded?

Neither. It is processed in this tab and not kept in local storage, so a reload clears it.

Related tools

Esc