JSON Escape and Unescape
ED-05Paste text to escape it for use inside a JSON string, or paste an escaped string to get the plain text back. Quotes, backslashes, line breaks and control characters are all handled.
Runs in your browser. Nothing is uploaded.
Text or JSON string content
Result
How to use it
- Paste your text into the input box, or open a text file (up to 5 MB) or drop it on the box.
- Choose Escape to make the text safe inside a JSON string, or Unescape to reverse it.
- Tick Add surrounding quotes if you want a complete JSON string value, or Escape non-ASCII if the output must be plain ASCII.
- Copy the result or download it as a .txt file.
What gets escaped
Escape replaces the double quote and the backslash, writes line breaks and tabs as \n and \t, and turns every other control character below U+0020 into a \u00XX escape. Characters outside ASCII are left as they are unless you tick Escape non-ASCII, which writes them as \uXXXX. An emoji is stored as two UTF-16 units, so it becomes a pair of escapes such as \ud83d\ude00. The forward slash is only escaped if you ask for it, because JSON allows both forms.
What Unescape accepts
Unescape reads the escapes the JSON standard defines: \" \\ \/ \b \f \n \r \t and \uXXXX. It accepts the text with or without the outer double quotes. It is strict on purpose. An escape such as \x41 or \' is not valid JSON and gets an error with the line and column. A raw line break inside the text is also rejected, because JSON strings must write it as \n. A lone surrogate escape that cannot form a character is reported as well.
Escaping text versus formatting a document
This page escapes the contents of one string. It does not read a whole JSON document, check its structure or re-indent it. If you have a full JSON file to tidy or validate, use the JSON Formatter on this site. If you are building JSON by hand, escape each text value here and place it between double quotes.
Error messages and what to do
| Message | What it means | Fix |
|---|---|---|
Unescaped double quote at line 1, column 9. Inside a JSON string it must be written as \". | A double quote appears inside the text without a backslash, so it would end the JSON string early. | Put a backslash before the quote, or press Escape to do it for you. |
Invalid escape "\q" at line 1, column 2. JSON allows only \" \\ \/ \b \f \n \r \t and \uXXXX. | A backslash is followed by a character that JSON does not accept as an escape. | Double the backslash to keep it as a backslash, or replace the escape with a \u sequence. |
A raw control character (U+000A) at line 1, column 2 is not allowed in a JSON string. Write it as an escape such as \n or \u000a. | The text holds a real line break, tab or other control character. JSON requires these to be written as escapes. | Press Escape on the original text first, then Unescape the result if you need it back. |
Questions people ask
How do I escape a string for JSON?
Paste the text and press Escape. Double quotes, backslashes, line breaks, tabs and other control characters are replaced with the escapes JSON requires. Tick Add surrounding quotes to get a complete string value you can paste straight into a JSON document.
How do I unescape a JSON string?
Paste the escaped text, with or without its surrounding double quotes, and press Unescape. Sequences such as \n, \" and \u00e9 turn back into the characters they stand for. Invalid escapes produce an error that shows where the problem is.
Which characters must be escaped in JSON?
The double quote, the backslash and every control character from U+0000 to U+001F. Everything else may appear as it is, including accented letters and emoji. The forward slash may be written as \/ but does not have to be.
Why does JSON escape emoji as two \u codes?
JSON escapes work on UTF-16 code units, and an emoji outside the Basic Multilingual Plane uses two of them, called a surrogate pair. For example, U+1F600 is written \ud83d\ude00. Unescape joins the pair back into one character. Without the ASCII option the emoji is left as it is.
Can JSON use single quotes or \x escapes?
No. JSON strings use double quotes only, and \x41 or \' are not valid escapes. Use \u0041 for the letter A. If you need a JavaScript string literal rather than JSON, use the JavaScript escape tool on this site instead.
What does the error Invalid escape mean?
The text has a backslash followed by a character JSON does not allow after a backslash, such as \q or \x. The error names the character and its line and column. Double the backslash to write a real one, or use \u with four hex digits.
About this tool
Escape turns quotes, backslashes, line breaks, tabs and other control characters into the escapes JSON requires, so the text can sit inside a double-quoted string. Characters outside ASCII are left as they are unless you tick the option, and emoji become a surrogate pair of two \u escapes. Unescape reverses it and accepts text with or without the surrounding quotes. It follows the JSON standard, so it rejects invalid escapes such as \x41 or \' and raw line breaks. It does not parse a whole JSON document; use the JSON Formatter for that.