JS String Escape / Unescape
Escape a string for safe embedding in JS code (handles \n, \t, \r, \" and non-ASCII Unicode). JSON-safe mode uses JSON.stringify rules. Reverse: unescape back to the original string. Runs in your browser.
Escape text for JavaScript-style string content or decode supported escape sequences back into text. An optional JSON mode uses JSON.stringify behavior for escaping, while the normal mode applies the tool’s explicit JavaScript-oriented replacements.
How to escape or unescape a JavaScript string
- Choose Escape or Unescape mode.
- Paste or type the source text.
- In Escape mode, optionally enable JSON mode.
- Review the converted output and copy it when needed.
What is escaped and unescaped
Normal Escape mode replaces backslashes, newlines, carriage returns, tabs, double quotes, single quotes, null characters, and characters from U+0080 through U+FFFF. Those non-ASCII BMP characters are written as four-digit \uXXXX escapes.
JSON mode uses JSON.stringify on the input string and removes the surrounding quote characters. Unescape mode wraps the entered escape text as a JSON string and parses it, so it supports JSON-compatible sequences such as \n, \t, \r, \\, \" and \uXXXX; invalid input reports an error.
Privacy and limitations
All conversion is performed locally in the browser. This tool converts string escape syntax only; it does not execute JavaScript, validate a complete source file, or guarantee that the output is appropriate for every language, template system, shell, database, or serialization format.
Frequently asked questions
What is the difference between normal and JSON mode?
Normal mode uses this tool’s replacement rules, while JSON mode uses JSON.stringify escaping and strips the surrounding quotes.
Does normal mode escape single quotes?
Yes. It converts single quotes to backslash-single-quote.
Does it escape non-ASCII characters?
Normal mode converts characters from U+0080 through U+FFFF to \uXXXX form.
Does unescape mode execute the result?
No. It parses escape syntax as a JSON string and outputs text.
Can every JavaScript escape sequence be decoded?
No. Unescape mode is limited by JSON string escape syntax.