How to escape a string for JSON
- Choose Escape to turn plain text into a JSON string, or Unescape to go the other way.
- Paste your text into Text. When escaping, untick Wrap in quotes if you only want the inside of the string.
- Copy the Result or download it as string.json.
Characters that must be escaped
| Character | Escaped as |
|---|---|
Double quote " |
\" |
Backslash \ |
\\ |
| Line feed (new line) | \n |
| Carriage return | \r |
| Tab | \t |
| Backspace | \b |
| Form feed | \f |
| Other control characters, U+0000 to U+001F | \u and four hex digits, like \u0001 |
Everything else can appear as it is. A Windows path is the case people trip over most: C:\Users needs every backslash doubled, as C:\\Users, or the parser reads \U as a broken escape.
Forward slashes and double escaping
The forward slash may be escaped as \/ but it doesn’t have to be. Some encoders, such as PHP’s json_encode by default, write \/ so that a </script> inside a string can’t end an inline script block. JSON.stringify leaves slashes alone, and unescaping turns \/ back into / either way.
Escaping text that’s already escaped doubles everything: \" becomes \\\". If you see runs of backslashes in a value, something escaped it twice. Unescape it once and check whether it reads correctly.