Skip to content

Text to Unicode

Transform text into Unicode escape sequences and decode them.

Text to Unicode

Runs entirely in your browser

This tool executes locally using standard browser APIs (for example window.crypto.getRandomValues or crypto.subtle where applicable). Your input is not transmitted to or stored on a ScriptPulse server. See How Calculations Work.

No data uploaded

What This Tool Does

  • Text to Unicode converts text into \uXXXX-style Unicode escape sequences — the notation JavaScript, JSON, and many other languages use to represent a specific character by its code point directly in source code or a string literal, rather than typing the character itself. This matters whenever you need to embed a character that's hard to type, easy to misread, or risky to include literally in a file that might be processed by tools sensitive to its actual byte encoding.
  • The genuinely tricky part this tool handles correctly is characters above the Basic Multilingual Plane (code points beyond U+FFFF, which includes most emoji): a single \uXXXX escape can only represent a 16-bit value, so JavaScript's string escape notation represents those characters as a surrogate pair — two \uXXXX escapes together, following a specific mathematical relationship to the actual code point — rather than a single escape. Getting that pairing arithmetic right is exactly the kind of detail that's easy to get subtly wrong by hand.

How It Works

  • For text-to-Unicode conversion, each character is read by its actual code point (not by raw UTF-16 code unit, so a character requiring a surrogate pair is still processed as one logical character).
  • For a code point within the Basic Multilingual Plane (up to U+FFFF), a single \uXXXX escape is produced directly from its hex value.
  • For a code point above U+FFFF, the code point is adjusted by subtracting 0x10000, then split into a high surrogate (0xD800 plus the adjusted value's upper 10 bits) and a low surrogate (0xDC00 plus the adjusted value's lower 10 bits) — the exact algorithm UTF-16 defines for representing supplementary-plane characters as a pair of 16-bit code units.
  • For Unicode-to-text conversion, \uXXXX escape sequences are parsed back and converted to their corresponding characters, reversing the process.

Usage

  1. Choose a direction — text to Unicode escapes, or Unicode escapes to text.
  2. Enter the text or \uXXXX-escaped content.
  3. The output updates automatically.
  4. Copy the result for use in source code, JSON, or wherever the escaped or decoded form is needed.

Examples

  • Converting an emoji into its JavaScript escape sequence to see the exact surrogate pair (two \uXXXX values) that represents it.
  • Converting a string containing an unfamiliar or hard-to-type character into escaped form for safe inclusion in source code.
  • Decoding a \uXXXX-escaped string found in a configuration file or log back into readable text to understand what it actually says.
  • Verifying by hand-checking the math that a specific surrogate pair correctly reconstructs the code point you expect, as a way to understand the UTF-16 surrogate algorithm concretely.

Real-World Use Cases

  • Embedding a specific character in JavaScript or JSON source code using its escape sequence, when the literal character is impractical to type or risky to include directly in a file with uncertain encoding handling.
  • Understanding exactly how a character above the Basic Multilingual Plane (many emoji, for example) is represented as a surrogate pair in JavaScript string escapes.
  • Decoding a \uXXXX-escaped string found in source code, a log file, or serialized data back into its actual readable characters.
  • Verifying that a surrogate pair you're seeing in code or debugging output actually corresponds to the character you expect, by converting it back to text.

Best Practices

  • Use escape sequences specifically when a character needs to be unambiguous in source code review or is genuinely hard to type reliably — for most text content, storing and transmitting the actual character (properly UTF-8 encoded) is simpler and equally correct.
  • When manually reasoning about a surrogate pair, remember the specific offset math (0xD800/0xDC00 base values, 0x10000 subtraction) rather than assuming any two \uXXXX values next to each other are automatically a valid pair.
  • Verify a decoded result matches the character you expected, especially when working with surrogate pairs, since a single mistyped hex digit in either half produces a different (or invalid) character entirely.
  • Prefer plain UTF-8 text over escape sequences for anything that doesn't specifically need them — escapes are a tool for specific situations (source code embedding, certain serialization contexts), not a general-purpose text representation.

Common Mistakes

  • Treating a supplementary-plane character's two \uXXXX escapes as two independent characters rather than a single surrogate pair representing one actual character.
  • Manually constructing a surrogate pair without following the exact 0xD800/0xDC00 offset algorithm, producing an invalid or incorrect pair that doesn't decode back to the intended character.
  • Assuming every character needs escaping for safe storage or transmission — properly UTF-8-encoded text handles the vast majority of cases without needing escape sequences at all.
  • Confusing a JavaScript \uXXXX escape (which represents a single UTF-16 code unit, requiring pairs for supplementary-plane characters) with Python's \UXXXXXXXX escape (which represents a full code point directly, no pairing needed) — the two notations are not directly interchangeable.

Limitations

  • This tool produces JavaScript/JSON-style \uXXXX escape notation specifically; other languages' escape conventions (such as Python's distinct \uXXXX versus \UXXXXXXXX forms) are not directly generated.
  • Decoding requires well-formed \uXXXX sequences — malformed or incomplete escape sequences will not decode correctly.
  • Very long input is processed in the browser and may affect responsiveness for extremely large text blocks.

Technical Reference Guide

  • The surrogate pair mechanism for representing code points above U+FFFF within UTF-16 is defined by RFC 2781, which specifies UTF-16 as an encoding of the broader Unicode/ISO 10646 character repertoire.
  • The Unicode Standard's core specification defines the Basic Multilingual Plane boundary (U+FFFF) and the supplementary planes above it that require surrogate pairs to represent in UTF-16.
  • JavaScript's specific \uXXXX string escape syntax is defined within the ECMAScript Language Specification, which relies on the same UTF-16 surrogate pair mechanism for characters outside the Basic Multilingual Plane.

FAQ

  • Why does an emoji produce two \uXXXX escapes instead of one?

    Most emoji live at code points above U+FFFF, outside the Basic Multilingual Plane. A single \uXXXX escape can only represent a 16-bit value, so UTF-16 (and JavaScript's escape notation) represents these characters as a surrogate pair — two 16-bit values that together encode the actual code point.

  • How is a surrogate pair calculated?

    The code point has 0x10000 subtracted from it, then the result is split: the high surrogate is 0xD800 plus the upper 10 bits, and the low surrogate is 0xDC00 plus the lower 10 bits. This exact algorithm is what lets a decoder reconstruct the original code point from the pair.

  • Is \uXXXX the same across all programming languages?

    No — JavaScript and JSON's \uXXXX represents a single UTF-16 code unit (requiring pairs for supplementary-plane characters), while some languages (like Python's \UXXXXXXXX, capital U, 8 digits) represent a full code point directly without needing surrogate pairs. Check your specific target language's convention.

  • Do I need to escape every non-ASCII character?

    No — properly UTF-8-encoded text handles non-ASCII characters correctly in virtually all modern systems without needing escape sequences. Escaping is useful for specific cases: embedding in source code for clarity, or contexts with uncertain encoding handling.

  • What happens if I decode a malformed escape sequence?

    Decoding requires well-formed \uXXXX sequences with valid hex digits; malformed or incomplete sequences won't decode correctly, since the parser can't reconstruct a valid code point from invalid input.

  • What's the difference between this tool and the Unicode Inspector?

    The Unicode Inspector shows you a code point's properties (decimal value, UTF-8 bytes) for characters you already have. This tool converts between actual text and its \uXXXX escape notation, including the surrogate pair math for characters outside the Basic Multilingual Plane.

Part of this Developer Hub

This utility is part of our comprehensive Encoding & Conversion topic workspace.

Explore foundational guidelines, technical specifications, and other interactive utilities related to this workflow.

Related Tools

Explore related utilities inside the Data Workshop workshop for complementary engineering workflows.

View all Data Workshop tools