Convert Unicode to String Literal
Convert Unicode to escaped string literals for JS, TS, Python, Go, Rust, C/C++, Java, JSON, Ruby. Bidirectional. Free, offline, client-side, secure.
- Runs in your browser
- Nothing uploaded
- Free, no sign-up
Convert Unicode text to a properly-escaped string literal for 9 programming languages - JavaScript, TypeScript, Python, Go, Rust, C/C++, Java (with surrogate pairs), JSON (RFC 8259), Ruby. Quote style configurable. Reverse direction parses common escape sequences back to text.
Per-character breakdown
How to Use Convert Unicode to String Literal
- Paste your text. Multi-line. Anything Unicode.
- Pick target language. Each has its own escape conventions - JS uses
u{...}ES2015 form; Python usesUXXXXXXXX; JSON requires surrogate pairs for non-BMP; Java always uses surrogate pairs; Go has both forms; Rust uses curly-brace; C/C++ usesUfor 8-digit. - Choose quote style. Double / single / backtick (JS template literal). The active quote character gets escaped inside the output.
- Toggle ASCII-safe. On: printable ASCII stays as-is. Off: everything escaped. Common control characters (
\n \t \r \b \f \v \0) always become their escape forms; backslash and the chosen quote always escape. - Toggle surround-with-quotes. On: output is paste-ready including the outer quotes. Off: just the escaped content without quotes (useful for concatenation).
- Read the grid. Char / codepoint / escape sequence / type (kept-ascii / control / unicode / special). Color-coded.
- Swap to decode. Parses JS/Python/Go/Rust/C escape sequences (
uXXXX,u{...},UXXXXXXXX,xNN,netc.) back to text. Surrogate pairs are combined automatically.
Frequently Asked Questions
Why are languages different?
Historical and syntactic. JavaScript ES2015 added u{XXXXX} for codepoints > U+FFFF. Pre-ES2015 JS only had uXXXX, requiring surrogate pairs for emoji. Python uses UXXXXXXXX (8-digit) for codepoints > U+FFFF. JSON has no support for u{...} at all – must use surrogate pairs. Java always uses surrogate pairs. Go and C have U with 8 hex digits. Each language’s parser only accepts its own variant – using the wrong escape format produces syntax errors.
What’s a surrogate pair?
UTF-16’s way of encoding codepoints above U+FFFF using two 16-bit code units. The high surrogate is in D800-DBFF, the low surrogate in DC00-DFFF. So 🌍 (U+1F30D) becomes 🌍. JSON and Java require this; modern JS/Python/Rust/Go let you write the codepoint directly in u{} or UXXXXXXXX. The tool handles the math for you.
What if my string contains the quote character I selected?
It gets escaped. With double-quote selected, every " in the input becomes ". Switch to single-quote and the input’s ' chars escape instead, leaving " chars unchanged. Pick the quote style your codebase uses to minimize escapes.
What’s ASCII-safe mode?
On (default): printable ASCII characters (a-z, A-Z, 0-9, common punctuation) stay literal in the output – your string is human-readable. Off: every character becomes an escape sequence – the output is dense but unambiguous about every codepoint. Off mode is useful when transmitting through systems that may modify whitespace or quote characters.
Why escape n t r etc.?
These control characters can’t appear directly inside most language string literals (the literal would end mid-character). Their backslash-escape forms are the standard way to embed them. Some languages allow raw newlines inside multi-line strings, but escape forms work universally.
Can I decode string literals from any language?
The reverse direction handles JS/Python/Go/Rust/C-style escapes universally: uXXXX, u{XXX}, UXXXXXXXX, xNN, plus the standard escapes (n t r b f v \ " ' `). Surrogate pairs are auto-combined. Outer quotes are stripped if present.
Why is JSON different?
RFC 8259 (JSON) only specifies uXXXX escapes – no u{...}, no xNN, no v, no