String Escape / Unescape
Escape or unescape strings for JavaScript and JSON literals: quotes, backslashes, newlines, tabs and \uXXXX. Two-way, free and fully private in your browser.
What is the String Escape / Unescape?
The ByteTools String Escape / Unescape tool converts any text into a safe JavaScript or JSON string literal and back again.
- Two-way escape and unescape in one tool
- Handles quotes, backslashes, \n, \r, \t, \b and \f
- Optional \uXXXX encoding for non-ASCII characters
- Decodes \uXXXX, \u{…} and \xHH sequences
- Clear error messages for malformed escape sequences
- 100% client-side — strings never leave your browser
How to use the String Escape / Unescape
- 1
Choose Escape to encode text, or Unescape to decode it.
- 2
Paste your string into the input box.
- 3
In Escape mode, optionally tick 'Escape non-ASCII characters as \uXXXX'.
- 4
Read the converted result below.
- 5
Copy the output straight into your code or JSON.
About the String Escape / Unescape
The ByteTools String Escape / Unescape tool converts any text into a safe JavaScript or JSON string literal and back again. Switch between Escape and Unescape modes to add or remove the backslash sequences that quotes, backslashes, newlines, tabs and control characters require.
In Escape mode it replaces special characters with \n, \t, \\, \" and, optionally, encodes every non-ASCII character as a \uXXXX sequence for maximum portability. In Unescape mode it decodes those same sequences — including \uXXXX, \u{…} and \xHH — back into the original readable text.
Everything runs locally in your browser, so your strings are never uploaded. It is ideal for pasting text into source code, building JSON payloads by hand, or decoding an escaped value from a log or config file.
Frequently asked questions
How do I escape a string for JavaScript or JSON?
Select Escape mode and paste your text. The tool replaces characters that would break a string literal — such as double quotes, backslashes and line breaks — with their escaped forms, giving you text you can drop straight between quotes in code or JSON.
What is the difference between escaping and unescaping?
Escaping adds backslash sequences so text is safe inside a string literal, turning a real newline into the two characters \n. Unescaping reverses this, converting \n back into an actual line break so you get the original readable text.
What does \uXXXX mean?
It is a Unicode escape that represents a character by its code point in four hexadecimal digits, for example \u00e9 for é. Escaping non-ASCII characters this way keeps strings safe to store or transmit through systems that only handle plain ASCII.
Why do I get an error when unescaping?
Unescaping fails when a sequence is malformed — for example a \u followed by fewer than four hex digits, or a string ending in a lone backslash. The error message names the problem sequence so you can correct it.
Does this work for both single and double quotes?
The escaper targets double-quoted JavaScript and JSON strings, escaping double quotes and backslashes. When unescaping it also understands escaped single quotes, so text copied from either quoting style decodes correctly.
Is my text uploaded when I convert it?
No. All escaping and unescaping happens in your browser with JavaScript, so nothing is sent to a server and your data stays private.
Guides for String Escape / Unescape
Related tools
JSON Escape / Unescape
Escape or unescape JSON string values online, or stringify text into a quoted JSON string. Handles quotes, backslashes, newlines and \uXXXX. Free and private.
Regex Tester
Test regular expressions online with live match highlighting, capture groups and flag toggles (g, i, m, s, u, y). Free, instant and 100% private in your browser.
Base64 Encoder
Encode text or files to Base64 instantly in your browser. UTF-8 safe, with a URL-safe Base64 option, copy and download. Free online Base64 encoder.
URL Encoder
Percent-encode text for URLs instantly. Switch between encodeURIComponent and encodeURI modes, see live output and copy the result. Free URL encoder.