Encoding and escaping

String escapewith explicit syntax

Escape and unescape in one editor, and keep the original text with undo.

String escape

Current content

Escape: text → escaped text; Unescape: escaped text → text. Each unescape handles one layer. Options apply to the next action; a failed conversion keeps the content.

Ctrl/Cmd+Enter: EscapeCtrl/Cmd+Shift+Enter: Unescape

Enter text or load an example. Empty input can be converted.

0 UTF-16 units

Character inspection

The table describes only the latest successful conversion: the value before escaping, or the restored value after unescaping. After a manual edit or an option change, the old table and report no longer describe the current text. Rows follow code points, and isolated surrogates are marked.

Conversion options

Choose a context explicitly. JSON uses strict string syntax; JavaScript accepts a documented subset. Unicode accepts only the selected escape form, one layer at a time. Options affect the next action and do not rewrite the current text.

Initial input: up to 1,048,576 UTF-16 units. Output and further processing of generated documents: up to 4,194,304 units. Empty input is valid; pasting may normalize line endings.

View original

Conversion stays in this browser; input is not uploaded. Undo history stays in this tab and is bounded for large documents.

String escape helps when a value copied from a log must become a JSON string, or a JavaScript literal needs to become readable text. A visible backslash followed by n differs from an actual newline: selecting the destination syntax makes that distinction explicit.

Use string unescape for one encoded layer at a time. The character table shows what the value contains, including invisible controls, supplementary emoji and isolated UTF-16 units that a normal text editor may conceal.

Why use String escape?

Match the receiving syntax

String escape keeps JSON escape and JavaScript escape separate. JSON uses double quotes and a narrower escape set; JavaScript offers a selected single- or double-quoted form. Body mode removes only the wrapper convention, not the syntax checks.

Quotes and a newline become escaped quote and newline sequences inside surrounding quotes.

See beyond the visible symbol

An emoji can be one code point and two UTF-16 units. Inspect the underlying value before exporting; isolated surrogate units remain identifiable instead of being silently replaced.

An emoji maps to the UTF-16 units D83D and DE00 above and the code point 1F600 below.

Choose syntax before converting

01

Check wrappers and quote style

The default produces a complete JSON literal with double quotes. Select Body only for a string without its outer quotes. For JavaScript, match the selected quote to the literal you are reading; the tool does not guess.

02

Convert the current text

Escape and Unescape both read the current text. Editing or changing options does not convert it. Ctrl/Cmd+Enter escapes, and Ctrl/Cmd+Shift+Enter unescapes. Each unescape removes one layer.

03

Keep the original and step back

The original is captured before the first conversion. Edits, conversions, restoring the original, examples and clearing share undo and redo. The character table and JSON report describe only that successful conversion and need a new run after a manual edit. Copy and TXT use the full current text, except when it contains isolated surrogates.

Inspect the representation and the value

Selective ASCII output

In JSON and JavaScript, enable non-ASCII escaping when the destination requires it. Otherwise readable Unicode remains readable. The tool can escape quotes and backslashes without normalizing the underlying text.

Two Unicode representations

Unicode escape mode encodes every character, including ASCII. Choose one \uXXXX per UTF-16 unit or \u{…} per code point; the decoder accepts only that selected notation and retains ordinary text.

Source locations for errors

Malformed sequences report a line and column where available. A rejected conversion does not return a repaired or partial string, so the next edit can target the offending input.

A report for exact review

The JSON report includes input, output, the underlying value, options and up to 100 character rows. Its escaped strings preserve isolated surrogates that a UTF-8 text export cannot retain unchanged.

Supported syntax and resource limits

One strict JSON string
JSON accepts standard escapes and \uXXXX only. It rejects raw C0 controls, unescaped double quotes, \xHH, \v and \u{…}. Literal mode permits surrounding space, TAB, CR and LF; body mode does not trim or remove quotes.
A limited JavaScript parser
JavaScript supports common escapes, \xHH, \uXXXX, \u{…} and line continuations. \0 cannot precede a digit. Raw LF and CR fail; raw U+2028 and U+2029 are retained. Identity escapes, octal, templates and expressions are outside this tool’s subset.
Unicode notation is explicit
Unicode decoding requires each backslash to start a valid escape in the selected form. Mixing \uXXXX and \u{…}, or using \n, fails. Brace values must not exceed 10FFFF; isolated surrogate values are preserved, not described as Unicode scalar values.
Surrogates are not repaired
If the current text contains isolated surrogates, Copy and TXT are disabled so export does not replace them. The JSON report of the latest successful conversion can still store the original units. Escaping that text into a legal ASCII form restores ordinary export. Pasting may normalize line endings.
Limits follow the current document
A first input allows 1,048,576 UTF-16 units. Output and further processing of a generated document allow 4,194,304, and a report allows 16,777,216. An oversize conversion fails as a whole. The editor keeps the full current text; the character table shows at most 100 rows and does not truncate the document.
No recursive decoding or code execution
Each run restores one layer. This page does not evaluate JavaScript, format JSON objects, import files, fetch URLs or sanitize HTML. String quoting alone does not guarantee safe insertion into an HTML script element. Pasting may normalize line endings.

String escape questions

How do JSON and JavaScript escaping differ?

JSON allows a small fixed set, including \n and \uXXXX, inside double-quoted strings. JavaScript also supports forms such as \xHH and single-quoted literals. This String escape tool deliberately rejects some valid JavaScript forms, including identity escapes, so its accepted subset stays explicit.

Why is escaped output longer?

A single newline becomes the two visible characters \n. Unicode output can represent one UTF-16 unit with six characters such as \u0041. These are longer written representations, not extra characters added to the restored value.

Can escaping and unescaping preserve the original value?

Yes, when the same context and form are used, the conversion preserves the UTF-16 value without normalization. Clipboard pasting may alter line endings. Use the JSON report if the restored result contains isolated surrogate units.

Are surrounding quotes included?

Complete literal includes the selected outer quotes; Body only does not. JSON always uses double quotes. Standalone Unicode mode has no surrounding quotes. Choose the matching form explicitly when decoding.

Can I restore an escaped string?

Click Unescape. Each click removes one layer from the current text, including edits you just made. The page does not unescape recursively or switch direction by itself. If the restored text contains isolated surrogates, copy and TXT stay disabled until you escape it into a legal form; the JSON report of that conversion keeps the original units.

Found a string edge case?

Try a representative string

Use String escape with a quote, a newline and an emoji, then inspect the underlying characters before exporting.