Home Tools Blog About

Convert Unicode to String Literal

In short

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

Type to begin.
🛡
100% PrivateNo server uploads, ever
InstantRuns in your browser
💧
No WatermarksClean output, always
🆓
Free ForeverNo accounts, no limits

How to Use Convert Unicode to String Literal

  1. Paste your text. Multi-line. Anything Unicode.
  2. Pick target language. Each has its own escape conventions - JS uses u{...} ES2015 form; Python uses UXXXXXXXX; JSON requires surrogate pairs for non-BMP; Java always uses surrogate pairs; Go has both forms; Rust uses curly-brace; C/C++ uses U for 8-digit.
  3. Choose quote style. Double / single / backtick (JS template literal). The active quote character gets escaped inside the output.
  4. 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.
  5. Toggle surround-with-quotes. On: output is paste-ready including the outer quotes. Off: just the escaped content without quotes (useful for concatenation).
  6. Read the grid. Char / codepoint / escape sequence / type (kept-ascii / control / unicode / special). Color-coded.
  7. Swap to decode. Parses JS/Python/Go/Rust/C escape sequences (uXXXX, u{...}, UXXXXXXXX, xNN, n etc.) 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 . For codepoints above U+FFFF, JSON requires the UTF-16 surrogate pair form (🌍 for 🌍). Common JSON parsing libraries handle this correctly; this tool emits the right form.

What about template literals in JS?

Pick backtick as the quote style. The tool escapes ` characters (and the ${ sequence – but you’d need to manually escape that in your code if intentional). Template literal syntax otherwise matches single/double-quote strings for escape sequences.

Is my text uploaded?

No. All escaping happens in your browser.

Offline?

Yes. The whole tool weighs about 18 KB, so once the page has loaded it runs without any network connection – every conversion happens locally in JavaScript on your device.

Keep going

Related Tools

All Unicode tools →
Share

Embed this tool

Add this free tool to your website. Copy and paste the code: