JSON String Escape and Unescape
Unescape one JSON string literal back to plain text, or escape plain text into a literal. The tool handles double quotes, backslashes, newlines, tabs and Unicode escapes in one pass. Choose Included when the outer double quotes are present, or Omitted for the inside of a literal. Editing Text chooses Escape; editing Escaped chooses Unescape. Invalid escapes are refused without a partial result. Whole JSON documents, programming-language string syntax and HTML embedding have different rules.
- Direction
- Quotes
- Length
- 36 characters
- Valid
- Yes
Unescaping one whole JSON string literal, surrounding quotes included: each escape becomes the character it stands for, once, and anything after the closing quote is refused.
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
- How do I unescape a JSON string?
- Paste it into the Escaped box with Direction set to Unescape, and the plain text appears in the Text box. Every escape becomes the character it stands for: \n a line break, \t a tab, \r a carriage return, \b a backspace, \f a form feed, \" a double quote, \\ a single backslash, \/ a forward slash and \u0041 the letter A. A pair such as \ud83d\ude00 is read as the one character it spells. If the text you have kept its surrounding double quotes, leave Quotes on Included; if it starts straight into the content, set Quotes to Omitted. Nothing is uploaded and there is no length limit: the reading happens in your browser.
- Should the surrounding double quotes be included or not?
- It depends on where the text came from, which is why it is a separate control rather than something this page guesses. A value copied out of a JSON file or an API response arrives as "like this", quotes and all, so Quotes is set to Included and the closing quote is what ends the literal. A value pulled out of a log line, a stack trace or an environment variable usually arrives without them, so Quotes is set to Omitted and the whole box is treated as the inside of a literal. The setting works the same way when escaping: Included wraps the result in quotes so it can be pasted straight into a JSON document, Omitted gives you the inside only, for somewhere that adds its own.
- Which characters have to be escaped in a JSON string?
- 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.
- Why does my text have \\n where a line break should be?
- Because it was escaped twice, and this tool will not silently undo that. Unescaping is one pass: the literal "a\\nb" holds a backslash and an n, so one pass gives back a backslash and an n rather than a line break. That is the honest answer, since the text really does contain those two characters. If you want the line break, unescape the result a second time yourself by copying it back into the box: two passes are two decisions, and the tool never takes the second one for you. The same rule runs the other way, so escaping text that already carries escapes and reads as a whole literal says so in the line under the boxes before it happens.
- Why is my literal refused, and what does the position mean?
- A literal is refused whole. Positions start at 1 and count UTF-16 string units, so an emoji can occupy two positions. Unsupported escapes such as \x, incomplete \uXXXX escapes, raw controls, missing quotes and extra values each have a specific error. Only JSON whitespace is allowed outside a quoted literal: spaces, tabs, carriage returns and line feeds. A non-breaking space outside the quotes is not valid JSON whitespace.
- Can I paste a whole JSON object or file into this?
- No, and the refusal says so: this tool reads one string literal, so an object, an array or a bare number is turned away rather than half handled. That keeps the job small and exact. If you have a whole document to read, indent or check, the JSON formatter linked below is the page for it, and it names the cause and the line when a document will not parse. Come back here when you have one string value out of that document and you want to see what it really says, or when you have a piece of text that needs to become one.
- Is anything I paste sent anywhere?
- No. The conversion happens in your browser, so there is no server in this, no account and nothing logged. The two settings, the direction and the quoting, are remembered in this browser so the tool opens the way you left it, and the text in the boxes is never written to storage or anywhere else. The Start over button above the tool forgets those two settings again. There is no size limit either: a one line value is as welcome as a log file with a hundred thousand escapes in it, and the only ceiling is your own device.
- Is JSON escaping enough to embed HTML or a script safely?
- 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 it force every Unicode character into a \uXXXX escape?
- No. Escaping keeps ordinary Unicode characters readable and only escapes required characters and lone surrogates. Unescaping accepts four-digit \uXXXX escapes, including surrogate pairs. There is no ASCII-only or HTML-safe JSON output option.
- Can it minify a document and then escape it?
- This tool treats its input as text and creates one string literal. It does not minify, parse, serialise or recursively unescape an object. Format or minify a valid document in the related JSON Formatter first, then paste that text here if you need to store the complete document inside a JSON string.
- How do I read JSON stored inside one quoted string?
- Unescape the complete quoted string once here, then copy the decoded document into the related JSON Formatter to check or format it. For example, a string holding {"name":"Ada"} becomes that document text after decoding. This is a manual two-tool workflow. Escaped fields inside an ordinary object are not recursively decoded, and unescaping does not validate the resulting document.
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.