String Escape Sequence Converter
Decode, encode, normalize or inspect JavaScript, JSON and C string escapes while keeping control characters, Unicode scalar values, UTF-16 surrogates and syntax-specific edge cases visible.
Conversion options
Converted text, syntax diagnostics, Unicode/UTF-16 inspection and export output will appear here.
The Backslash Does Not Mean the Same Thing in Every String Format
\n is familiar across several languages, but the sets quickly diverge. JSON allows a deliberately small escape grammar. JavaScript adds forms such as \xHH, \u{...}, line continuation and some identity escapes. C has octal, greedy hexadecimal and \UXXXXXXXX universal-character names.
Decoding every backslash with one universal regex can make malformed JSON look valid or turn C bytes into invented Unicode characters. The selected syntax determines which transformations are allowed.
JSON Has No \xHH or \u{1F680} Escape
JSON strings use \uXXXX UTF-16 code-unit escapes. A supplementary character such as 🚀 is represented with two \uXXXX surrogate escapes when escaped, not the JavaScript code-point form \u{1F680}.
A useful validation check is to wrap generated JSON string content in double quotes and pass it through JSON.parse. That catches a quote, backslash or control character that would make the generated JSON string invalid.
One Visible Character Can Be Two UTF-16 Code Units
JavaScript strings are indexed as UTF-16 code units. Many emoji and historic-script characters are outside the Basic Multilingual Plane and use a surrogate pair, so a single Unicode code point can make string.length increase by two.
The inspection table shows both a code-point row index and the original UTF-16 offset so copied error positions and JavaScript indexes are easier to reconcile.
Lone Surrogates Are a Real Interoperability Edge Case
JSON grammar can carry escaped UTF-16 surrogate code units even when they do not form a valid pair. Software differs in how well such strings survive encoding, databases, APIs and Unicode normalization.
Lone surrogate escapes are kept visible during diagnosis rather than silently replaced or combined. That makes the malformed or non-interoperable code-unit sequence easier to trace back to its source.
Newline Normalization Must Happen Before Encoding Plain Text
Once a newline has become the two visible characters \ and n, changing LF to CRLF no longer affects it. The encode path therefore normalizes actual line separators first and only then turns them into escape sequences.
Normalize mode does the reverse in a deliberate order: decode → normalize actual line breaks → encode using the selected syntax.
C Hex Escapes Are Greedy
In C, \xconsumes hexadecimal digits until the run ends; it is not inherently limited to two digits. The resulting value is then interpreted through the C implementation's character model.
The C mode here models an ordinary unprefixed string, so an octal or hexadecimal escape must fit the range of unsigned char. Larger values stay visible as high-severity findings instead of being assigned an invented browser-Unicode meaning. Prefixed u8, u, U and L literals have different corresponding ranges and are outside this mode.
C Universal-Character Names Are Not General Control-Byte Escapes
C places extra constraints on \uXXXX and \UXXXXXXXX. Surrogates are not permitted, values above U+10FFFF are not permitted, and most code points below U+00A0 cannot be written as universal-character names.
Control characters therefore use the ordinary C escapes such as \a, \n and \t, or a numeric octal/hex escape when no simple spelling exists. Fixed three-digit octal output avoids both an invalid low-value \u escape and the greedy-length problem of \x.
Removing Quotes Is Not the Same as Parsing a Language Literal
When “unwrap matching quotes” is enabled, only the first and last matching quote characters are removed before escape conversion. JavaScript source is not evaluated, adjacent literals are not concatenated, template expressions are not processed, and a C compiler's source/execution character sets are not simulated.
Primary reference for JavaScript string escape sequences, Unicode escapes, hex escapes and line continuations.
Defines JSON string escaping and the interoperability concern around unpaired surrogate sequences.
Reference for Unicode code points, scalar values and UTF character representation.
Public WG14 draft showing C escape-sequence grammar and universal-character-name constraints, including the low-value, surrogate and U+10FFFF limits.
