Unicode Encode / Decode
Convert between text and \uXXXX escape sequences
Unicode escapes: when to use \uXXXX, and how to convert without breaking surrogate pairs
What a Unicode escape is
The notation \uXXXX writes a character as pure ASCII: a \u followed by four hexadecimal digits that form the code point. The Chinese character 中 has code point U+4E2D, so its escape is \u4e2d. A string that originally contained non-ASCII characters becomes a sequence safe to transport through any ASCII-only environment.
Its natural home is source code and configuration files. Java's .properties files were historically read as ISO-8859-1, so Chinese had to be escaped. The JSON spec permits raw UTF-8 characters, yet some older toolchains still demand fully ASCII output. JavaScript strings sometimes need escaping to avoid encoding issues in certain bundling or injection scenarios. In all of these, \uXXXX is the lingua franca that keeps the bytes honest.
It is not the same as URL or HTML encoding
| Scheme | Form | Used in |
|---|---|---|
| Unicode escape | \u4e2d | source code, JSON, Java properties |
| URL percent-encoding | %E4%B8%AD | URLs, query parameters |
| HTML entity | 中 or 中 | HTML/XML content |
Note that URL encoding targets UTF-8 bytes (a Chinese character is usually three %XX groups), while the Unicode escape targets the code point (one Chinese character is one \uXXXX). The same character has a different length and different content under the two systems, which is exactly why mixing them produces nonsense.
Surrogate pairs: when the code point exceeds U+FFFF
A \uXXXX escape only has four hex digits, so it can represent at most U+FFFF. Emoji and some CJK extension characters live above that range — for example, 😀 is U+1F600 — and must be written as a surrogate pair of two escapes: \ud83d\ude00.
This is the single most error-prone step. If a decoder processes surrogate pairs "one four-digit block at a time," it splits a single emoji into two invalid characters and emits garbage. The reverse problem is just as real: if the text already contains a lone high surrogate — a common signature of corrupted data — encoding and decoding cannot reconstruct the original. Whenever you handle text with emoji, run a bidirectional check with the same tool to be certain.
How to use this tool
- Paste text into the input and click convert to generate the
\uXXXXsequence. - To reverse, paste an escape sequence and click the other button to restore readable text.
- Use the swap button to move the output back into the input for continuous processing.
The tool also supports both uppercase and lowercase hex output (\u4E2D versus \u4e2d), because some languages and toolchains are case-sensitive about it. The entire conversion happens in the browser, and no data leaves the page.
FAQ
What are escape sequences good for?
In Java properties, some JSON configs, and JS strings, \uXXXX is often used to represent non-ASCII characters and avoid encoding issues.