How to escape a string for JSON
- Choose the mode: Escape, Unescape, Stringify JSON or Parse stringified.
- Type or paste the input; the result appears immediately. When escaping, decide whether to add the surrounding quotes and whether to write non-ASCII characters as
\uXXXX. - Copy the result, or press Swap to reverse the operation and check the round trip.
JSON escape sequences
| Character | Escaped |
|---|---|
Double quote " | \" |
Backslash \ | \\ |
| Line feed (new line) | \n |
| Carriage return | \r |
| Tab | \t |
| Backspace, form feed | \b, \f |
| Other control characters U+0000–U+001F | \u0000 … \u001f |
| Any character (optional) | \uXXXX, e.g. é → \u00e9, 😀 → \ud83d\ude00 |
Slash / (optional) | \/ |
Single quotes never need escaping in JSON, because JSON strings always use double quotes.
Stringified JSON
Stringified JSON is a JSON document stored inside a JSON string – for example an API field like "payload": "{\"id\":7}", or JSON saved in a database column, an environment variable or a log line. Stringify JSON creates such a string from a document; Parse stringified unwraps it, even when it was stringified twice, and formats the result.
- JavaScript:
JSON.stringify(text)escapes,JSON.parse(literal)unescapes. - Python:
json.dumps(text)andjson.loads(literal). - PHP:
json_encode($text)andjson_decode($literal).
Frequently asked questions
Which characters must be escaped in JSON?
Only the double quote, the backslash and the control characters U+0000 to U+001F, such as line breaks and tabs. Everything else – including é, 中 and emoji – may appear as it is in UTF-8 JSON.
Why do I see \u00e9 instead of é?
Some programs write every non-ASCII character as a \uXXXX escape. Both forms mean the same; Unescape turns the escapes back into readable text.
What is the difference between escaping and stringifying?
Escaping turns any text into a JSON string literal. Stringifying first checks that the input is valid JSON, minifies it and then escapes it, so the result is a string that contains a JSON document.
Can I unescape a string without the outer quotes?
Yes. Paste the content with or without the surrounding quotes; stray unescaped quotes and real line breaks are tolerated as well.