Switch between JSON, JavaScript, and Regex modes to escape raw multiline text, Windows file paths, or regex metacharacters—or unescape double-encoded log strings containing \n, \t, \", and \uXXXX sequences.
Structured application logs often serialize a JSON payload inside another JSON string field, burying stack traces under layers of \" and \\n escapes. Similarly, passing dynamic user search phrases straight into new RegExp(query) breaks whenever input contains dots, brackets, or question marks.
This utility separates the distinct escaping grammars of JSON (RFC 8259), JavaScript source literals (including U+2028/U+2029 line separators and \u{...} code points), and RegExp metacharacters so you never over- or under-escape across boundaries.
String Escaping Bugs in Production Code
01. Using \' Inside JSON Strings
JavaScript allows escaping single quotes as \', but RFC 8259 JSON forbids it—JSON.parse rejects \' with a SyntaxError. Always pick JSON mode when generating payloads for REST APIs.
02. Forgetting Regex Metacharacters in Dynamic Filters
Searching for "$19.99 (USD)" inside new RegExp() treats $, ., (, and ) as regex anchors and groups instead of literal text. Always run Regex Escape before interpolating untrusted literals.
03. Windows Backslashes Consuming Next Character
A path like C:\new\test embeds \n (newline) and \t (tab) unless every backslash is doubled to \\. Escaping raw paths first prevents silent string corruption.
Escaping Rules Across Grammars
| Mode | Escaped Sequences | Typical Use Case |
|---|---|---|
| JSON | \", \\, \b, \f, \n, \r, \t, control chars \u00xx | Embedding multiline text inside a JSON property |
| JavaScript | Both quotes, \\, whitespace, \0, \u2028, \u2029 | Generating JS/TS source templates & unescaping logs |
| Regex | Escapes . * + ? ^ $ { } ( ) | [ ] \\ | Safely matching literal filenames, prices, or URLs |
Worked Engineering Examples
Unescaping a Stringified Stack Trace From JSON Logs
Error: ECONNREFUSED\n at TCPConnectWrap (\"/app/db.ts\":42)
Error: ECONNREFUSED
at TCPConnectWrap ("/app/db.ts":42) JSON Unescape expands escaped newlines and quotes back into a clean, readable stack trace.
Escaping a Literal Price for JavaScript RegExp
Price: $49.00 (USD)?
Price: \$49\.00 \(USD\)\?
Every regex operator receives a leading backslash so new RegExp() matches the exact characters.
Frequently Asked Questions
Does JSON Escape wrap the output in outer quotation marks?
No. It outputs the inner escaped content so you can paste directly inside existing quotes, while JSON Unescape accepts strings with or without outer quotes.
Why does JavaScript mode escape U+2028 and U+2029?
Line Separator (U+2028) and Paragraph Separator (U+2029) are valid raw characters in JSON but caused syntax errors in pre-ES2019 JavaScript string literals and break some bundlers.
Can JavaScript Unescape decode ES6 \u{1F680} and \x41 escapes?
Yes. JavaScript Unescape supports \n, \r, \t, \0, \xHH, \uHHHH, and ES6 braced \u{...} Unicode code point escapes.
What happens if I paste an invalid JSON escape like \a into JSON Unescape?
The parser reports an explicit invalid JSON escape sequence error so you can switch to JavaScript mode or fix the malformed backslash.