Encoding and escaping

String escapewith explicit syntax

Choose a string context before escaping quotes or restoring a value.

String escape

Input

Result

Character inspection

Encoding inspects the source value; decoding inspects the restored value. Rows follow code points, with isolated surrogate units marked separately.

Conversion stays in this browser; input is not uploaded.

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 is decoded per run.

Input: 1,048,576 UTF-16 units; output: 4,194,304 units. Pasting may normalize line endings.

Enter text or load an example.

Preview the current result as the next input, then apply to change direction. One Undo restores the previous state. Reverse is unavailable when the result exceeds the 1,048,576-unit input limit.

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

Control refresh timing

Automatic conversion runs 350 ms after edits. Turn it off to show Convert, or use Ctrl/Cmd+Enter. An input or option change makes the old result stale and disables export until conversion succeeds.

03

Review values before replacing input

Example, Clear and Reverse open a replacement preview. Apply confirms it; Undo restores one snapshot. The result preview stops at 20,000 UTF-16 units, and character inspection starts at 50 entries with up to 100 available.

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 result contains isolated surrogates, Copy and TXT are disabled. Use the JSON report for lossless storage. An ASCII escaped result can be exported normally. No Unicode normalization is applied.
Full values, bounded previews
Input is limited to 1,048,576 UTF-16 units and output to 4,194,304. The report limit is 16,777,216 units. Oversize conversions fail as a whole; the 20,000-unit text preview and 100-row table do not truncate the underlying result.
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?

Choose Unescape string and the syntax that produced it. A successful conversion removes one layer. For nested escaping, inspect the result before intentionally processing it again; automatic recursive decoding is not provided.

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.