What does it mean to unescape JSON?
Unescaping is escaping in reverse. It takes the backslash sequences inside a JSON string, such as \n, \" and \u00e9, and turns them back into the characters they stand for: a line break, a double quote and the letter é.
You usually meet escaped text when JSON has been stored inside something else. A log line, a database column or an API field holds a whole JSON document as one long string, so every quote picks up a backslash and the result is hard to read.
Where escaped JSON usually comes from
- Application logs that print a request or response body as a string.
- Database columns that store JSON as plain text.
- Message queues and event streams that carry JSON as text.
- API responses where one field contains another JSON document.
- Values copied from a browser's network tab, a debugger or a terminal.
- Config files and environment variables that keep JSON on a single line.
A quick example
This came out of a log file:
{\"name\":\"Sam\",\"note\":\"Line one\\nLine two\"}After unescaping, the quotes are back to normal and you have JSON you can read and format. The \n inside the note stays as it is, because it belongs to the inner document and is still valid there:
{"name":"Sam","note":"Line one\nLine two"}Double-escaped JSON
Sometimes JSON gets turned into a string more than once, for instance when one service stores a payload inside another service's JSON field. After one round of unescaping you still see backslashes. That doesn't mean the tool missed something. Paste the result back into the input to remove another layer, and repeat until the text looks like ordinary JSON.
Why you get an invalid string error
The tool follows JSON's rules strictly, so these are the usual reasons it refuses an input:
- An unescaped double quote in the middle of the text. Inside a JSON string every quote must be written
\". If you have plain text with raw quotes, run it through JSON Escape first. - An escape sequence JSON doesn't allow. Only
\",\\,\/,\b,\f,\n,\r,\tand a backslash followed by u and four hex digits are valid. Escapes borrowed from other languages, like\'or\x41, fail. - An incomplete Unicode escape. A backslash and a u must be followed by exactly four hexadecimal digits.
- A backslash at the very end. It has nothing to escape, so the string is invalid.
Unescaping in your own code
In code, wrap the escaped text in double quotes and parse it as JSON:
const text = JSON.parse('"' + escaped + '"');import json
text = json.loads('"' + escaped + '"')Is it safe to paste private text here?
Decoding happens in your browser. The text you paste is processed on your own device and isn't sent to our servers, so log lines and API responses stay with you. The Privacy Policy covers the details.