String Escape and Unescape Online
This free tool escapes and unescapes string literals for the contexts developers paste strings into every day: JSON, JavaScript, Java, C/C++, Python, and a plain Unicode (\uXXXX) mode. Escaping turns a raw string into a safe literal body — replacing quotes, backslashes, newlines, tabs, and other control characters with the backslash sequences each language understands. Unescaping does the reverse, turning \n, \t, \uXXXX, \xXX, and octal escapes back into the characters they represent.
It escapes the string content only and never adds the surrounding quotes, so you can drop the result straight into a literal of your choosing. Non-ASCII text and astral characters such as emoji are handled correctly, including surrogate pairs in Unicode mode. Everything runs locally in your browser, so the strings you paste are never uploaded.
How to use String Escape / Unescape
- Choose a Context — JSON string, JavaScript string, Java, C/C++, Python, or Unicode (\uXXXX).
- Choose a Direction: Escape to turn raw text into an escaped literal, or Unescape to turn an escaped literal back into raw text.
- Type or paste your text into the input box; the result appears live in the output box as you type.
- Copy the result, download it as a .txt file, or press Use as input to move it across and flip the direction to verify a round-trip.
Contexts and their rules
- JSON string — escapes " and \ plus the named controls \b \f \n \r \t, and encodes any other control character (U+0000 to U+001F) as \u00XX, following RFC 8259. Forward slashes are left as-is.
- JavaScript string — escapes the quote characters " ' and the backtick, plus \, the named controls including \v, and other controls as \xXX. Unescaping also understands \uXXXX, the ES6 code-point form \u{...}, \xXX, and legacy octal.
- Java — escapes " ' \ and the named controls \b \f \n \r \t, encoding other controls as \uXXXX. Unescaping understands \uXXXX and octal escapes.
- C / C++ — escapes " ' \ and the named controls \a \b \f \n \r \t \v, encoding other controls as a 3-digit octal \ooo (this avoids C's greedy \x hex escape, which would swallow following hex digits). Unescaping understands \xXX, \uXXXX, \UXXXXXXXX, and octal.
- Python — escapes " ' \ and the named controls \a \b \f \n \r \t \v, encoding other controls as \xXX. Unescaping understands \xXX, \uXXXX, \UXXXXXXXX, and octal.
- Unicode (\uXXXX) — converts every non-ASCII character to one or more \uXXXX escapes and leaves ASCII untouched, the same idea as Java's native2ascii.
Escaping the content, not the quotes
This tool transforms the body of a string literal, not the whole literal. It does not wrap the output in quotes, because the delimiter you use (double, single, or backtick) is up to you. That is also why, in the language modes, both single and double quotes are escaped: the escaped text is then safe to paste inside whichever quote style your literal uses.
Raw: She said "hi".\nBye JSON: She said \"hi\".\nBye Python: She said \"hi\".\nBye
Unicode, emoji, and surrogate pairs
In Unicode mode each non-ASCII character is emitted as a \uXXXX escape per UTF-16 code unit. Characters outside the Basic Multilingual Plane — most emoji, for example — are made of two code units, so they become a surrogate pair of two \uXXXX escapes, and the tool reassembles that pair correctly when unescaping. The language modes leave printable non-ASCII characters as literal UTF-8 text; switch to Unicode mode when you specifically want an ASCII-only \uXXXX form.
😀 -> 😀 é -> \u00E9
Handling malformed escapes
Unescaping is forgiving. If it meets a broken escape — a \u without four hex digits, a \x without two, or a stray backslash at the end of the input — it shows a warning describing the problem but still produces a best-effort result rather than failing. Unknown letter escapes follow each language's own rule: JSON flags them, JavaScript and Java drop the backslash, and Python keeps the backslash and the character together.
Related terminology
- Escape sequence
- A backslash followed by one or more characters that stands in for a character which is hard to type or has special meaning in a string, such as \n for a newline or \" for a double quote.
- String literal
- Text written directly in source code between quotes. Escaping makes arbitrary text safe to place inside a literal without breaking it.
- Control character
- A non-printing character in the range U+0000 to U+001F, such as tab, newline, or null, which is written using an escape sequence inside a string.
- Unicode escape
- A \uXXXX (or \u{...} / \UXXXXXXXX) sequence that names a character by its code point, letting non-ASCII text be written using only ASCII.
- Surrogate pair
- Two UTF-16 code units (a high and a low surrogate) that together encode one character above U+FFFF, such as an emoji — written as two \uXXXX escapes.
Frequently asked questions
- Does this add the quotes around my string?
- No. It escapes the string content only, so you add the surrounding quotes yourself. That lets you paste the result into a double-quoted, single-quoted, or backtick literal as needed, which is why both quote characters are escaped in the language modes.
- What is the difference between the JSON and JavaScript contexts?
- JSON follows RFC 8259: it escapes only the double quote, backslash, the named controls \b \f \n \r \t, and other control characters as \u00XX. JavaScript additionally escapes the single quote and backtick and uses \xXX for controls, and its unescaper also understands \uXXXX, \u{...}, \xXX, and octal escapes.
- Does it handle emoji and other non-English characters?
- Yes. The language modes keep printable non-ASCII characters as literal UTF-8 text, and the Unicode mode converts every non-ASCII character to \uXXXX, correctly emitting and re-reading surrogate pairs so emoji round-trip exactly.
- What happens if my escaped string is malformed?
- The tool never crashes. It shows a warning that names the problem — for example a \u with too few hex digits or a trailing backslash — and still returns a best-effort decoded result so you can see what parsed and fix the rest.
- Can I use this to escape text for HTML or URLs?
- No — this tool is for programming-language and JSON string literals. For HTML entities use the HTML Encode/Decode tool, and for percent-encoding in URLs use the URL Encode/Decode tool.
- Is my text sent to a server?
- No. All escaping and unescaping happens in your browser with JavaScript, so nothing you paste is uploaded, logged, or leaves your device.