How to use
- In Escape, paste the text you want to put inside a JSON string. A sample with quotes, a line break and a backslash is already filled in.
- The result is wrapped in double quotes by default. Turn off Wrap in double quotes if you only need the value.
- Turn on Escape non-ASCII as
\uXXXXto turn Hangul or emoji into codes such as\ud55c, and Escape/as\/when the JSON goes inside an HTML</script>block. - To read an already escaped string, switch to Unescape and paste it. The surrounding double quotes are optional.
- Use Use result as input to hop between the two directions and check the round trip.
What gets escaped
A JSON string cannot contain certain characters as they are, so they are written with a backslash.
| Character | Escape | Note |
|---|---|---|
Double quote " |
\" |
so it does not end the string |
Backslash \ |
\\ |
so it does not start an escape |
| New line | \n |
raw line breaks are not allowed in a JSON string |
| Tab | \t |
|
| Carriage return | \r |
|
| Backspace, form feed | \b, \f |
|
| Other control characters (U+0000 to U+001F) | \u0001 style |
|
Slash / |
\/ |
optional, valid either way |
A two-line text with He said "hi" followed by C:\dir becomes He said \"hi\"\nC:\\dir. Single quotes are not escaped in JSON.
Common uses
- Putting a JSON document in a string field: when an API takes JSON as a string value, escaping
{"a":"한글","b":[1,2]}gives"{\"a\":\"한글\",\"b\":[1,2]}". - Reading logs full of \n: paste them into Unescape and they turn into real line breaks.
- Avoiding encoding trouble: if a system cannot be trusted with UTF-8, use the ASCII-only option, which turns
한😀into\ud55c\ud83d\ude00. Emoji become two\ucodes (a surrogate pair). - U+2028, U+2029 and unpaired surrogates can cause trouble in JavaScript, so they are always written as
\uregardless of the options.
Unescape rules
- The escapes it reads are the JSON standard ones:
\" \\ \/ \b \f \n \r \t \uXXXX. Forms that JSON does not have, such as\x41, or a\uwithout four hex digits, are reported as errors with line and column. - It undoes one layer at a time.
\\nbecomes the two characters backslash and n, and needs a second pass to become a line break. - The tool does not use
JSON.parse, so raw line breaks mixed into the input are accepted rather than rejected.
Related tools
- JSON Formatter: pretty-print and validate JSON.
- Unicode Converter: switch between characters and
\uD55Ccodes. - HTML Entity Converter: escaping for HTML documents.
- URL Encoder / Decoder: percent-encoding for addresses.
FAQ
How do I write a new line inside a JSON string?
Write it as the two characters \n. A raw line break breaks the JSON. The Escape mode converts it for you.
How do I put double quotes inside a JSON value?
Put a backslash before each one: \". The backslash itself must be written \\.
Is JSON escape the same as JSON.stringify?
Nearly. This tool lets you tune the output (ASCII-only, slash, quote wrapping) and writes \u codes in lowercase hex. Both read back as the same text when parsed as JSON.
Why does Unescape report an error?
There is an escape JSON does not have (\x, \' and so on), or the text ends with a lone backslash. Use the line and column in the message to find and fix it.
Is my text uploaded?
No. Conversion happens in your browser and nothing is sent to a server.