Escape and Unescape JSON Strings
ED-46Paste text and click JSON escape to get a version that is safe inside a JSON string. Paste an escaped string and click JSON unescape to read the original text.
Runs in your browser. Nothing is uploaded.
Text or JSON string content
Result
How to use it
- Paste your text, or the escaped JSON string, into the input box.
- Optionally add surrounding quotes, escape non-ASCII as \uXXXX, or escape forward slashes.
- Click JSON escape or JSON unescape.
- Copy the result into your JSON or code.
What the escape does
JSON strings cannot contain a raw double quote, a backslash or a control character. Escape writes \" and \\ for the first two, and \n, \t, \r, \b and \f or a \u escape for control characters. Text outside ASCII is left alone unless you tick the option, in which case an emoji becomes two \u escapes. Forward slashes are only escaped if you ask.
Strict unescape
Unescape reads the text with or without outer double quotes. It follows the JSON standard, so escapes such as \x41 and \' are errors, and so is a raw line break inside the string, each reported with its position. It works on a piece of text, not on a whole JSON document. To format a document, use the JSON formatter instead.
Error messages and what to do
| Message | What it means | Fix |
|---|---|---|
Invalid escape | A backslash is followed by a character JSON does not allow as an escape. | Use only \" \\ \/ \b \f \n \r \t or \uXXXX, or double the backslash. |
Unescaped double quote | A double quote appears inside the string without a backslash. | Write it as \". |
Questions people ask
How do I escape a string for JSON?
Paste the text and click JSON escape. Double quotes, backslashes and control characters such as line breaks and tabs are replaced with their escapes, so the result can sit between double quotes in a JSON document. Tick the quotes option to get the quotes added.
How do I unescape a JSON string?
Paste the escaped string, with or without the surrounding quotes, and click JSON unescape. Escapes like \n, \" and \u00e9 become the characters they stand for. An invalid escape is reported with its line and column.
Do I need to escape forward slashes in JSON?
No. A plain / is valid in a JSON string, and \/ is also allowed. Escaping it is only needed in special cases, for example when JSON is placed inside an HTML script tag. The option is off by default.
Which characters must be escaped in JSON?
The double quote, the backslash and every control character below U+0020, including line breaks and tabs. Everything else may appear as it is. This tool escapes those and, if you ask, non-ASCII characters and slashes as well.
Why is my unescaped text rejected?
JSON is stricter than JavaScript. Escapes like \x41 or \', and raw line breaks or tabs inside a string, are not valid. The error names the position, so you can fix or replace that spot and run it again.
About this tool
Escape writes the escapes the JSON standard requires inside a double-quoted string: the double quote, backslash and the control characters, with \n, \t and the other short forms where they exist. Characters outside ASCII stay as they are unless you tick the option, and an emoji then becomes two \u escapes. Unescape accepts text with or without the outer quotes and follows the standard strictly, so \x41, \' and raw line breaks are errors with a position. It escapes a piece of text, not a whole JSON document. To format a document use the JSON Formatter. Nothing is uploaded.