Unicode Escaper

Turn characters into \u escape sequences.

Reverse
Input
TEXT input
Output
Result
Options

About this tool


Escaping converts characters into \u sequences so text survives a channel that cannot carry them, a source file that must stay ASCII, a legacy build tool, or a config format with an uncertain encoding.

The escape syntax differs by language, and the differences matter for characters outside the Basic Multilingual Plane. JSON has no syntax for them at all and needs surrogate pairs; JavaScript added \u{...}; Python uses \U with eight digits; CSS uses a bare backslash and hex digits.

How to use it

  1. Paste or upload your textDrop a file onto the input pane, use the file picker, or paste the text directly.
  2. Adjust the options if neededThe defaults suit most input; open Options to change the behaviour.
  3. EscapePress Escape, or use Ctrl+Enter (Cmd+Enter on macOS).
  4. Copy or downloadCopy the result, or download it as a .txt file.

Worked examples


Each example below is executed against this tool by the test suite, so what you see is what the tool actually produces.

JSON style with a surrogate pair

Input

héllo 😀

Output

h\u00e9llo 😀

The emoji needs two escapes because JSON has no syntax for code points above U+FFFF.

JavaScript style

Input

😀

Output

\u{1f600}

Modern JavaScript can express the code point directly.

What to watch for


The details that decide whether a conversion is correct, and where information can be lost without any error being raised.

The four escape styles
JavaScript uses \u00e9 for BMP characters and \u{1f600} for astral ones. JSON supports only the four-digit form, so an emoji must be written as a surrogate pair: 😀. Python uses \U0001f600 with eight digits. CSS uses \e9 followed by a space to terminate the escape.
Surrogate pairs explained
Characters above U+FFFF cannot fit in the four hex digits JSON allows, so they are encoded as two surrogate code units. That is why one emoji becomes two \u escapes in JSON. Splitting a string between those two halves produces a lone surrogate, which is invalid, a common source of corruption when truncating text.
Escaping only what is necessary
By default ASCII characters are left as they are, so the output stays readable and only the unusual characters are escaped. Turn that off to escape everything, which some legacy pipelines require.

Limitations


  • CSS escapes are terminated with a trailing space, which is required by the CSS syntax.
  • Lone surrogates in the input cannot be escaped meaningfully and are passed through.
  • Processing happens in your browser, so very large inputs are bounded by available memory. Files above roughly 10 MB are handled but will feel slower, and multi-hundred-megabyte files are better suited to a command-line tool.

Questions


Why does one emoji produce two escapes?
In JSON style, characters above U+FFFF must be written as a surrogate pair. Switch to JavaScript style for the single \u{...} form.
Which style should I choose?
JSON for JSON documents, JavaScript for .js source, Python for .py, CSS for stylesheets. The BMP forms are largely interchangeable; the astral forms are not.