Xerobit

Unicode Escape Converter: Encode and Decode Unicode Sequences

Use this tool to escape unicode characters in any string or decode a unicode escape sequence back into readable text. It supports JavaScript \uXXXX, ES6 \u{...}, U+ code point notation, and HTML hex entities, handling surrogate pairs automatically. Everything runs locally in your browser so no data is uploaded.

When unchecked, basic printable ASCII (space through tilde) is left as-is during encoding.

Result

How to use the unicode escape converter

  1. Paste your text into the Input text field, or paste an already-escaped string if you want to decode it.
  2. Select Encode to convert plain text to a unicode escape sequence, or Decode to reverse the process.
  3. Choose your target format: JavaScript \uXXXX, ES6 \u{...}, U+ notation, or HTML hex entities.
  4. Check Escape ASCII characters too if you need every character encoded, not just non-ASCII ones.
  5. Copy the result from the output box. The conversion happens instantly in your browser.

How unicode escape sequences work

A unicode escape sequence represents a character by its numeric code point rather than its visual glyph. In JavaScript, the classic form is \uXXXX where XXXX is exactly four hexadecimal digits. For example, the letter e with an acute accent (é) has code point U+00E9, so its escape is \u00e9.

This works perfectly for the Basic Multilingual Plane (BMP), which covers code points U+0000 through U+FFFF. Characters beyond that range, such as most emoji, require either two \uXXXX sequences called a surrogate pair, or the newer ES6 syntax \u{XXXXX} which accepts one to six hex digits directly.

Surrogate pairs explained

UTF-16 encodes characters above U+FFFF using two 16-bit code units: a high surrogate (range D800 to DBFF) and a low surrogate (range DC00 to DFFF). To escape unicode characters like the globe emoji (U+1F30D) in the classic \uXXXX format, the converter performs this math:

  1. Subtract 0x10000 from the code point: 0x1F30D - 0x10000 = 0xF30D.
  2. The high ten bits become the high surrogate: 0xD800 + (0xF30D >> 10) = 0xD83C.
  3. The low ten bits become the low surrogate: 0xDC00 + (0xF30D & 0x3FF) = 0xDF0D.

The result is \ud83c\udf0d. Python's json.dumps() produces the same paired output when ensure_ascii=True. When decoding, this tool detects valid surrogate pairs and merges them back into a single character.

Format comparison table

Different languages and contexts expect different ways to write a unicode escape. Here is how the character é (U+00E9) and the globe emoji (U+1F30D) look across the four supported formats:

Formaté (U+00E9)🌍 (U+1F30D)
JavaScript \uXXXX\u00e9\ud83c\udf0d
ES6 \u{...}\u{e9}\u{1f30d}
U+ notationU+00E9U+1F30D
HTML &#x...;é🌍

The U+ notation is typically used in documentation and character maps rather than source code. HTML hex entities are parsed by browsers but not by JavaScript engines directly.

Practical use cases

Developers frequently need to escape unicode when preparing strings for JSON payloads, configuration files, or legacy systems that only accept ASCII input. If you are working with broader string escaping needs, the string escape tool handles quotes, newlines, and tabs alongside unicode. For web-specific markup, the HTML escape tool converts angle brackets and ampersands safely.

Another common scenario is debugging garbled text. If a database returns \u00e9 instead of é, pasting that string into this converter in decode mode reveals the original text immediately. You can also verify that your output matches what Python would produce: running 'café'.encode('ascii', 'backslashreplace') yields b'caf\\xe9', while json.dumps('café') gives "caf\u00e9", matching the JavaScript format here.

Common mistakes when converting

One frequent error is confusing UTF-8 byte escapes with unicode code point escapes. The character é is two bytes in UTF-8 (0xC3 0xA9), but its code point is 0x00E9. A unicode escape always refers to the code point, never the raw bytes. If you need byte-level conversions, look at tools like text to binary or base64 encoding instead.

Another pitfall is broken surrogate pairs. If a string contains a high surrogate without a following low surrogate, it is technically invalid UTF-16. This converter treats isolated surrogates as individual code units when encoding, and leaves them unmerged when decoding, preventing data loss even on malformed input.

Worked examples

ExampleInputResult
Encode emoji to JS escapesInput text: Hello 🌍; Mode: encode; Format: js; Escape ASCII characters too: noHello \ud83c\udf0d
Decode ES6 escapeInput text: caf\u{00E9}; Mode: decode; Format: es6; Escape ASCII characters too: nocafé
Encode accented text to HTML entitiesInput text: naïve; Mode: encode; Format: html; Escape ASCII characters too: nonaïve
Encode all characters including ASCIIInput text: A; Mode: encode; Format: js; Escape ASCII characters too: yes\u0041

FAQ

What does it mean to escape unicode?

To escape unicode means replacing a character with a textual representation of its code point, such as \u00e9 for é. This ensures the string contains only ASCII characters, which avoids encoding issues in systems that do not support UTF-8 natively.

What is the difference between \uXXXX and \u{XXXXX}?

The \uXXXX form uses exactly four hex digits and requires surrogate pairs for characters above U+FFFF. The \u{XXXXX} form, introduced in ES6, accepts one to six hex digits and represents any code point directly without surrogate pairs.

How do I convert unicode to escape sequence format in Python?

In Python, you can use json.dumps(text, ensure_ascii=True) to get \uXXXX escapes identical to the JavaScript format. Python's text.encode('unicode_escape') is different: it writes \xe9 for é, \u20ac for € and \U0001f30d for the globe, and it also escapes newlines and backslashes.

Does this tool handle emoji correctly?

Yes. Emoji live outside the Basic Multilingual Plane, so they are encoded as surrogate pairs in the JavaScript \uXXXX format and as single values in the ES6 \u{...} format. Both are handled accurately.

Can I decode a string that mixes escaped and normal characters?

Yes. In decode mode, the tool scans for recognized escape patterns like \uXXXX or &#x...; and converts them, leaving any surrounding plain text untouched.

Is my text sent to a server?

No. The conversion runs entirely in your browser using JavaScript. Nothing is uploaded anywhere.

What is U+ notation used for?

U+ followed by hex digits is a standard way to reference a unicode code point in documentation, character charts, and bug reports. It is not a programming language escape syntax.

Which escapes can the decoder read?

Decode mode reads only the format you pick: \uXXXX (including surrogate pairs), \u{...}, U+XXXX, or hexadecimal HTML entities like é. Other escapes such as \n, \xe9 or decimal entities like é are left unchanged; use the string escape tool for those. In U+ notation each escape is separated by a single space, and the encoder escapes a space or hex digit that directly follows a U+ code so the text decodes back exactly.