Unicode escape

Unicode escape

Convert between text and \uXXXX escape sequences (surrogate/emoji safe)

Computed in your browser

Choose four-digit UTF-16 or braced code-point format before encoding. Use four-digit format for JSON; decoding accepts both forms.

Example

Input

中文

Example result

\u4e2d\u6587

Select the four-digit format. Decode both sequences to recover the text.

Technical details & limits

A four-digit \uXXXX escape represents one UTF-16 code unit; code points above U+FFFF need a surrogate pair. Braced escapes represent a code point up to U+10FFFF, but are not valid JSON string escapes. This tool does not replace JSON.stringify's handling of quotes and backslashes.

About this tool

Escape and unescape Unicode characters using four-digit UTF-16 sequences or braced code-point notation. Choose non-ASCII-only or all-character escaping to inspect source, configuration and logs.

Use cases

  • Convert Chinese / emoji in source to pure ASCII \u escapes.
  • Decode a stream of `\u5927\u7237` in logs back to readable text.

How to use

  1. Paste text or a string with \u escapes.
  2. Click Escape to encode, Unescape to decode.

Notes

Printable ASCII is left alone by default. Code points above U+FFFF use `\u{XXXXXX}` braces (not surrogate pairs).

FAQ

How do UTF-16 escapes differ from Unicode code point escapes?
UTF-16 mode represents code units, while code point mode represents a complete Unicode code point directly. A four-digit escape uses 4 hexadecimal digits for each code unit; a character beyond U+FFFF requires 2 surrogate code units. Choose the representation supported by the receiving language. The shorter-looking code point notation is not universally interchangeable with surrogate escapes, particularly when the destination is a JSON string.
Can Unicode code point escapes be used directly in JSON?
JSON strings accept four-digit Unicode escapes but do not accept the brace-style code point notation. A basic-plane character uses 1 four-digit escape, while a supplementary character requires 2 surrogate escapes. Choose UTF-16 mode when preparing this representation for JSON. Quotes, backslashes, and control characters still need proper JSON serialization, because converting Unicode escapes alone does not produce a complete safely encoded JSON string value.
Why is Unicode escaping not a replacement for JSON serialization?
Unicode escaping changes character notation but does not perform every transformation required for JSON string serialization. The largest valid code point is U+10FFFF, and four-digit mode uses 4 hexadecimal digits per code unit. Input may also contain quotes, backslashes, or control characters that need additional handling. Use a JSON serializer when constructing a complete JSON value, rather than inserting this tool's output between quotation marks directly.

Related tools

Unicode escape · Convert between text and \uXXXX escape sequences (surrogate/emoji safe)
Unicode escape — Tool illustration · dayeku.com