How to Escape and Unescape Strings for JS and JSON
To escape a string for JavaScript or JSON, choose Escape mode, paste your text, and copy the result — the tool replaces quotes, backslashes, newlines and tabs with the backslash sequences a string literal needs. To reverse it, switch to Unescape mode. The ByteTools String Escape / Unescape tool does both directions in one place, and every conversion runs in your browser so your strings are never uploaded.
This tutorial covers each step, explains what the escaped forms mean, and shows when to turn on \uXXXX encoding.
What escaping actually does
A string literal in code is wrapped in quotes, so any character that would clash with those quotes — or break across a line — has to be written as a backslash sequence instead. A real line break becomes the two characters \n, a tab becomes \t, a double quote becomes \", and a backslash itself becomes \\. Escaping adds those sequences so text drops safely between quotes; unescaping strips them back out to recover the original readable text.
Step-by-step: escaping text
- Select Escape mode. This tells the tool to encode rather than decode.
- Paste your string. Drop in the raw text — a multi-line message, a path with backslashes, anything with quotes.
- Optionally tick 'Escape non-ASCII as \uXXXX'. Turn this on when the text must survive systems that only handle plain ASCII.
- Read the output. The converted literal appears below, ready to paste between quotes.
- Copy it into your code or JSON. One click and it is on your clipboard.
Step-by-step: unescaping text
Going the other way is just as quick. Switch to Unescape mode and paste an escaped value — perhaps a string pulled from a log file, a config, or a JSON payload. The tool decodes \n, \t and friends back into real characters, and it understands the three main Unicode forms: \uXXXX (four hex digits), \u{…} (variable length) and \xHH (two hex digits). The readable original appears below. If a sequence is malformed, you get a clear error naming the problem rather than silent corruption.
Common escape sequences at a glance
| Character | Escaped form | Meaning |
|---|---|---|
| New line | \n | Line break |
| Tab | \t | Horizontal tab |
| Double quote | \" | Quote inside a string |
| Backslash | \\ | Literal backslash |
| é (non-ASCII) | \u00e9 | Unicode code point |
When to use \uXXXX encoding
Leave non-ASCII escaping off for normal work — modern JSON and JavaScript handle UTF-8 accented characters and emoji directly, and the text stays readable. Turn it on when a string has to travel through older systems, email headers, or anything that mangles non-ASCII bytes: encoding é as \u00e9 keeps it portable. When you unescape later, those sequences decode straight back to the original characters.
Try the String Escape / Unescape — free and 100% in your browser.
FAQ
Do I need Escape or Unescape mode?
Use Escape when you have raw text and want a safe string literal to paste into code or JSON. Use Unescape when you already have an escaped value — with \n, \uXXXX and so on — and want the readable text back.
Will it break my JSON if I paste a whole object?
The tool escapes or unescapes the text you give it as a string value; it is not a JSON formatter. Paste the string content you want to encode, not the surrounding braces, and drop the result into your object as a value.
Why did unescaping throw an error?
A sequence is malformed — for example \u followed by fewer than four hex digits, or a string ending in a lone backslash. The message points at the offending sequence so you can fix it and run it again.
Is my text sent anywhere?
No. All escaping and unescaping happens locally in your browser with JavaScript, so nothing leaves your device — safe for tokens, config values and internal strings.
Related free tools
- JSON Escape / Unescape — focused on JSON string values.
- Base64 Encoder — encode binary or text to Base64.
- URL Encoder — percent-encode strings for URLs.
- Regex Tester — build and test patterns against sample text.
Built by ByteVancer
ByteTools is a free product of ByteVancer, a software and web development studio building web apps, SaaS and custom software. If developer tools like this speed up your day, see what ByteVancer can build for your product.
Recommended reading
String Escape and Unescape: Real Developer Use Cases
Real scenarios for escaping and unescaping strings: hand-building JSON, decoding log values, pasting text into source code and porting data between systems.
String Escaping Tips and Common Mistakes to Avoid
Pro tips for escaping JS and JSON strings: double-escaping traps, lone backslashes, when to use \uXXXX, and how to debug malformed escape errors fast.
Yes or No Generator: Real Use Cases and Examples
From beating decision paralysis to games and classrooms, see real use cases and examples for a random yes or no generator.
Yes or No Generator Tips and Common Mistakes
Get better decisions from a random yes or no generator. Pro tips, when to add Maybe, and the common mistakes to avoid when picking answers.