JSON escape / unescape
What is a Json Escape Unescape?
A JSON string value is wrapped in double quotes, so certain characters inside it must be escaped: double quotes, backslashes and control characters such as newlines and tabs. Forgetting one produces invalid JSON. This tool escapes any text for use inside a JSON string, and unescapes JSON string content back into plain text.
How to use it
- Paste plain text and escape it to get a JSON-safe string.
- Or paste an escaped string and unescape it to read the original text.
Example
Plain text over two lines:
He said "hi"
Path: C:\tempEscaped for JSON:
He said \"hi\"\nPath: C:\\tempThe quotes become \", the line break becomes \n and the single backslash becomes \\.
JSON escape sequences
\"double quote and\\backslash\nnewline,\rcarriage return,\ttab\bbackspace and\fform feed\uXXXXany Unicode character by its UTF-16 code unit, such as\u00e9for é- The forward slash may be escaped as
\/but does not need to be.
Common situations
- Putting a multi-line message, SQL query or HTML snippet into a JSON config or API body.
- Reading log lines where JSON was double-encoded, such as a string full of
\". - Single quotes never need escaping in JSON.
In code, prefer JSON.stringify() or your language's JSON library instead of escaping by hand.
Frequently Asked Questions
Which characters must be escaped in JSON?
Double quotes, backslashes and control characters such as newlines, carriage returns and tabs.
Do single quotes need escaping in JSON?
No. JSON strings use double quotes, so single quotes are allowed as they are.
Why does my log show text full of backslash quote sequences?
The JSON was probably encoded twice. Unescape it once to get the inner JSON.
How do I escape strings in code?
Use your language's JSON library, such as JSON.stringify in JavaScript or json.dumps in Python.