When you embed arbitrary text inside a JSON string, certain characters must be escaped or the JSON becomes invalid. This tool escapes text into a spec-correct JSON string body and unescapes it back, so you can move data in and out cleanly.
How it works
Escaping applies the JSON string rules in order. The backslash and double quote
get short escapes, the common control characters get their named escapes, and any
other control character becomes a \uXXXX sequence:
\ -> \\ " -> \"
newline -> \n tab -> \t carriage return -> \r
backspace -> \b form feed -> \f
other controls (< U+0020) -> \u00XX
Unescaping reverses this: it reads each backslash sequence, expands the known
escapes and \uXXXX references, and rejects malformed escapes with an error.
Complete escape table
| Character | Escaped form | Notes |
|---|---|---|
Double quote " | \" | Required — terminates the string otherwise |
Backslash \ | \\ | Required — starts an escape sequence otherwise |
| Newline (U+000A) | \n | Very common in multi-line text |
| Tab (U+0009) | \t | |
| Carriage return (U+000D) | \r | |
| Backspace (U+0008) | \b | Rare |
| Form feed (U+000C) | \f | Rare |
| Other U+0000–U+001F | \u00XX | Required for all control chars below space |
Forward slash / | \/ | Optional — JSON allows either form |
| Non-ASCII (optional) | \uXXXX | Only needed for pure-ASCII output |
When do you actually need this?
A few situations where this tool is particularly useful:
Building JSON by string concatenation. Generating JSON by concatenating strings is generally discouraged in favour of JSON.stringify, but when you must — for example in a shell script or a template — every user-supplied value needs its quotes and backslashes escaped before inclusion.
Embedding JSON inside an HTML script tag. The closing sequence </script> inside a JavaScript string terminates the tag early in HTML. Escaping / as \/ prevents this. This tool’s slash-escape option handles it.
Storing JSON strings in JSON. When a JSON field’s value is itself a JSON string (a common pattern in logging or event systems), every " and \ in the inner JSON must be escaped for the outer JSON parser. For example, the value {"a":1} must be stored as "{\"a\":1}".
Debugging escaped data. When you receive escaped JSON from an API and need to read the actual content, unescape it here instead of parsing it in code.
Tips and notes
The backslash must be escaped before the quote, or you would double-escape an
already-escaped quote. The forward slash never needs escaping in JSON, so it is
left alone by default; turn on slash-escaping only when embedding JSON inside an
HTML script tag, where </ could otherwise close the tag early. For pure-ASCII
output across systems with shaky encoding, enable the ASCII-safe option to emit
every non-ASCII character as \uXXXX.