What is JSON escaping?
JSON strings are delimited by double quotes, so any ", \, or control character inside them must be escaped or the parser breaks. JSON escape converts special characters into valid escape sequences: quotes, backslashes, newlines, tabs and control chars become \", \\, \n, \t, and so on.
It's essential when embedding user text, Windows paths, multiline logs, or stack traces inside a JSON payload. Everything runs 100% in your browser.
Edge cases & gotchas
- Output is the escaped body only, not a quoted literal (no surrounding
"). Use Stringify if you want the quotes too. - Invalid escapes like
\qor\xare not valid JSON; only the defined sequences below are legal. - Literal (raw) newlines and tabs are illegal inside JSON strings. They must become
\n/\t. - Forward slash is left unescaped by default (valid); some tools force
\/. - Backslash is escaped first (
\\) to avoid mangling other sequences. - Repair-aware parsing tolerates messy input on the unescape round-trip.
Escape sequence reference
| Sequence | Character | Meaning |
|---|---|---|
\" | " | Double quote |
\\ | \ | Backslash |
\/ | / | Forward slash (optional) |
\n | LF | Newline / line feed |
\t | TAB | Horizontal tab |
\r | CR | Carriage return |
\b | BS | Backspace |
\f | FF | Form feed |
\uXXXX | any | Unicode code point, 4-digit hex |
How to use
Examples
Quotes + newline + tab (edge case)
He said "hello" Line 2 tabbed
He said \"hello\"\nLine 2\ttabbed
Windows path (backslash)
C:\Users\Name\file.txt
C:\\Users\\Name\\file.txt
Unicode / control char
©
\u00a9
FAQ
Escape vs stringify: what's the difference?
Escape outputs only the escaped string body (no surrounding quotes). Stringify wraps a full JSON value in double quotes and escapes it, producing a complete string literal.
Do forward slashes need escaping?
No. \/ is legal JSON but optional; / is valid unescaped, so we leave it as / by default.
How do I escape Unicode?
Non-ASCII and control characters can be emitted as \uXXXX with 4-digit hex. Emoji and characters above U+FFFF need surrogate pairs (two \uXXXX).
Why do I get "Unexpected token" errors?
Usually a raw newline or an unescaped " inside a string. Escape the text first so those become \n and \".
What about double escaping?
Extra backslashes (\\n where you wanted \n) mean the text was escaped twice. Unescape once to fix it.
Is my data uploaded?
No. Escaping runs entirely client-side: zero network requests, verifiable in DevTools.