JSON Escape
Turn plain text into one JSON string literal with its outer double quotes included. Quotes and backslashes are escaped, and line breaks and tabs become \n and \t. Apostrophes, forward slashes, ampersands and ordinary Unicode stay readable because JSON does not require them to be escaped. Use Omitted if another serializer will add the outer quotes. This output is JSON text; embedding it in HTML or JavaScript requires the destination’s rules.
- Direction
- Quotes
- Length
- 44 characters
- Valid
- Yes
Escaping the text into one JSON string literal, surrounding quotes included, so the result can be pasted straight into a JSON document.
Type in either box: editing the text side escapes, editing the literal side unescapes, and the conversion runs once either way. Length counts the characters of the converted side. Positions in a refusal count UTF-16 units from the start of the box, beginning at 1; an emoji can occupy two positions.
JSON string escape reference
The optional surrounding double quotes are separate from the string body. This is JSON encoding, not HTML or shell escaping.
| Character | JSON string body |
|---|---|
| Double quote | \" |
| Backslash | \\ |
| Line feed | \n |
| Tab | \t |
| Carriage return | \r |
| Backspace | \b |
| Form feed | \f |
| NUL | \u0000 |
| Forward slash | / (\/ is also accepted) |
| Apostrophe | ' (no escape required) |
| Ampersand | & (no escape required) |
| Letter é | é (\u00e9 is also accepted) |
Common questions
- Which characters does this JSON encoder escape?
- Double quotes and backslashes must be escaped, along with controls below U+0020. Named escapes are \b, \t, \n, \f and \r; other controls and unpaired UTF-16 surrogates are written as \uXXXX. Ordinary é, 日本語 and emoji remain as Unicode text. A forward slash, apostrophe, ampersand, comma, colon and braces need no escape inside a JSON string. The reader also accepts the optional escaped forward slash \/. Escaping a lone surrogate makes the literal well-formed JSON text; decoding it can still produce that same lone surrogate.
- Should I escape a single quote or forward slash?
- Neither needs an escape in a JSON string. A single quote is left as an apostrophe, not written as an invalid backslash-apostrophe escape. A slash stays /, although \/ is accepted when decoding.
- How do I escape a newline or Windows path?
- Paste the actual newline or path into Text. Newlines become \n, and each backslash becomes a doubled backslash. The tool does one pass and warns when text already looks like an escaped JSON literal.
- Can I put the result directly into HTML?
- No. This encoder leaves <, > and & unchanged, and it does not neutralise a closing script tag. JSON string rules are separate from HTML text, HTML attributes, JavaScript source and SQL quoting. Store JSON as JSON, and use the target environment’s serializer or escaping rules when embedding it elsewhere. HTML entity conversion is a different job.
- Does this page overwrite my saved direction and quote choice?
- The Escape and Included presets apply while this page is open. Each preset value is saved only after you edit that control; other remembered settings still restore. Text is never stored.
Exact conversion by the JSON string rules, so what comes out parses as one string literal and reading it back returns the text you started with. Unescaping takes exactly one valid literal and names the position where an invalid one stops.