How do I escape characters in JSON?
Advanced Topics
Inside a JSON string, certain characters must be escaped with a backslash so the parser does not misread them, most importantly the double quote and the backslash itself. Escaping lets you store quotes, newlines, tabs, and any Unicode character safely.
Escape sequences
| Sequence | Meaning |
|---|---|
\" | Double quote |
\\ | Backslash |
\n | New line |
\t | Tab |
\r | Carriage return |
\/ | Forward slash (optional) |
\uXXXX | Unicode character (hex) |
Example
{
"quote": "She said \"hello\"",
"path": "C:\\Users\\me",
"line": "first\nsecond"
}
In code, you rarely escape by hand. JSON.stringify() (JS) or json.dumps() (Python) escapes everything correctly for you. See parsing JSON in JavaScript.
Unbalanced quotes or a stray backslash? The validator flags the exact spot.
Still Have Questions?
Check out our other FAQ topics or return to the JSON Copilot app