Developer utilities

JSON strings, escaped correctly.

Turn any text into a valid JSON string literal, or reverse one and see exactly where a bad escape sits. Nothing leaves your browser.

Advertisement

Text or JSON string

To unescape, paste a literal with or without its surrounding quotes. Raw line breaks are control characters and are rejected there, as RFC 8259 requires.

Result

Escape or unescape to see the result.

Worked examples

JSON inside JSON. The text {"id":7,"note":"a\nb"} (with a literal backslash and n) escapes to "{\"id\":7,\"note\":\"a\\nb\"}". Parse that once and you get the inner text back; parse the inner text and you get the object.

JS and C# source. The output uses only \" \\ \b \f \n \r \t and \uXXXX, which are also string escapes in JavaScript and in C# regular (non-verbatim) string literals, so a wrapped result can be pasted into source code. ECMAScript has accepted U+2028 and U+2029 inside string literals since ES2019, so they need no special case. In a C# verbatim string (@"...") you would instead double each quotation mark.

Rules used

Per RFC 8259 section 7, quotation mark, backslash and U+0000 to U+001F must be escaped. Control characters without a short form are written \u00XX. Characters outside the Basic Multilingual Plane are written as a UTF-16 surrogate pair (the RFC example is U+1D11E as \uD834\uDD1E). Unpaired surrogates are always escaped here, since they cannot be encoded as valid UTF-8. The slash is optional and off by default. Unescaping accepts the nine escapes in the RFC grammar (\" \\ \/ \b \f \n \r \t \uXXXX) and reports the line, column and offset of the first violation.

Sources: RFC 8259, The JSON Data Interchange Format (December 2017); TC39 JSON superset proposal (ES2019); Microsoft C# escape sequences. Rules checked against the RFC text 2026-10-01.

FAQ

Which characters must be escaped?

Quotation mark, backslash and U+0000 to U+001F. Nothing else is required.

Do I need to escape the forward slash?

No. \/ is legal but a bare slash is also valid; some serializers escape it to keep </script> out of inline HTML.

How do emoji appear in ASCII-only output?

As a surrogate pair of two \uXXXX escapes, 12 characters in total.

Is this the same as JSON.stringify?

With default options the output matches JSON.stringify on a string, except that hex digits are uppercase (both are valid).

Advertisement
Advertisement
Listening…