Skip to main content

Encoding & Escaping / Encoding & Escaping

JSON Escape and Unescape

JSON Escape turns any text into a valid JSON string literal — quotes, backslashes and control characters handled — and reverses the process to recover the original text. It exists because hand-written escapes are the single most common reason a string fails to parse. Nothing is uploaded.

Sponsored

This space is reserved for a sponsor.

Sponsored

This space is reserved for a sponsor.

How to use

  1. 1

    Paste the raw text

    Type or paste the string you need to embed in JSON: a message with quotes, a path with backslashes, a snippet with newlines. The tool reads it as you type and shows the escaped form live.

  2. 2

    Escape it into a JSON string

    Press escape to wrap the text in quotes and convert every special character into its JSON escape sequence — a double quote becomes \", a backslash becomes \\, a newline becomes \n. The result is safe to drop inside any JSON document.

  3. 3

    Unescape a JSON string literal

    Paste a JSON string that already contains escapes and press unescape to recover the readable original. This is useful when you have a serialised value and want to see the text it actually represents.

  4. 4

    Copy the result

    Copy the escaped or unescaped text straight to your clipboard. No request is made and nothing is stored; the transform runs entirely in your browser.

Key facts

  • Mandatory escapesA double quote and a backslash must always be escaped, and all control characters (U+0000–U+001F) must be escaped rather than written raw.Source:RFC 8259 §7
  • Forward slashThe solidus / may be escaped as \/ but is not required to be. Most serializers leave it unescaped.Source:RFC 8259 §7
  • Null characterU+0000 is not allowed in JSON at all, even as an escape, so a string carrying a null byte must be cleaned before serialising.Source:RFC 8259 §7
  • Standard lineageRFC 8259 (2017) is the Standards-Track replacement for the earlier RFC 7159 draft; both require control characters to be escaped. The practical escaping rules are unchanged.Source:RFC 8259 / RFC 7159

Frequently asked questions

When do I actually need to escape a string?

Any time the text contains a character that JSON reserves. A double quote ends the string, so any quote inside the content must become \". A backslash itself starts an escape, so it must become \\. Control characters — tab, newline, carriage return, and anything below U+0020 — are not allowed raw and must be escaped as \t, \n, \r and so on. Leaving any of these unescaped is the most common reason a perfectly good-looking string fails to parse.

Should I hand-write escapes or use JSON.stringify?

Always use JSON.stringify (or the equivalent in your language) rather than writing escapes by hand. Hand-written escapes are easy to get wrong: a missed backslash, a wrongly doubled quote, or a control character left raw all produce output that looks fine and then fails at parse time. JSON.stringify applies every rule correctly and consistently, which is exactly why this tool escapes the same way it does.

What does the JSON spec require for control characters?

RFC 8259 states that control characters (U+0000 through U+001F) MUST be escaped; they may not appear literally in a JSON string. The null character U+0000 is not permitted in JSON at all, even escaped. The backslash, double quote and the control-character escapes are mandatory; the forward slash / may be escaped as \/ but is not required to be.

Is my text uploaded?

No. Escaping and unescaping run entirely in your browser, with no request made and nothing stored on any server. You can paste confidential strings without any of the text leaving the page, which matters because the text you are escaping often comes from user input, logs or private data that you would not want copied into someone else's system.

Related tools

Sponsored

This space is reserved for a sponsor.