What unstringifying means
When JSON is stored inside a string, every double quote in it is written as \", every line break as \n and every backslash as \\. You see this in log files, message queues, webhook payloads, browser developer tools and database columns that hold JSON as text. It is valid, but hard to read:
"{\"name\":\"Ada\",\"tags\":[\"admin\",\"dev\"]}"
Unstringifying reverses the escaping and gives you the original value. If that value is JSON, this tool also formats it so you can read it.
How to use it
- Paste the escaped string into the left box, press Open file, or press Sample.
- The result appears on the right as you type.
- Set the options:
- Unescape nested strings keeps going when the result is itself another escaped string. It is on by default.
- If the result is JSON lets you choose 2 spaces or 4 spaces of indentation, or Leave as is.
- Press Copy, or Download to save the result as a text file.
The line under the boxes says whether the result is valid JSON and how many layers were unescaped.
Examples
The string above, with If the result is JSON set to 2 spaces, becomes:
{
"name": "Ada",
"tags": [
"admin",
"dev"
]
}
Escaped text without outer quotes works too. This input:
Line one\nLine two\t(tabbed)
gives two lines, with a real tab before (tabbed):
Line one
Line two (tabbed)
Unicode escapes are decoded. "Café 東京" becomes Café 東京.
Double-encoded strings
Sometimes data is stringified twice. The backslashes pile up:
"\"{\\\"event\\\":\\\"signup\\\",\\\"user\\\":7}\""
With Unescape nested strings on, the tool unescapes both layers and reports “Unescaped 2 layers”. With Leave as is selected, the result is:
{"event":"signup","user":7}
With Unescape nested strings off, it stops after one layer and you see the inner string, still escaped:
"{\"event\":\"signup\",\"user\":7}"
That is useful when you want to see exactly what each layer contained.
Error messages
If the input is not a valid JSON string, you get the line and column of the problem. Real examples:
| Input | Message |
|---|---|
"bad \q escape" |
Line 1, column 6: Invalid escape sequence \q |
He said "hi" |
Line 1, column 9: Found a double quote that is not escaped as \" |
"unterminated |
Line 1, column 1: Unterminated string: the closing double quote is missing |
JSON allows only these escapes: \", \\, \/, \b, \f, \n, \r, \t and \u followed by four hex digits. Escapes from other languages, such as \x41 or \', are not valid JSON. Press Show in input to jump to the problem.
How it works
The tool reads your input as a JSON string literal, adding the outer quotes if they are missing. It decodes the escapes using the JSON rules. If the result starts with a double quote and is itself a valid JSON string, and Unescape nested strings is on, it decodes again. Finally, if the result is a JSON object or array, it is formatted with the indent you chose. Numbers inside are kept exactly as written. Everything happens in your browser.
Tips
- If the result is not valid JSON, it is shown as plain text, which is correct for strings that were never JSON to begin with.
- Copy a value straight from a log line, including the quotes, to avoid missing a character at either end.
- If you get stray
\rcharacters in the output, the original text had Windows line endings.
Other ways to do it
JavaScript. JSON.parse(str) decodes one layer. Call it again on the result for a double-encoded value, then JSON.stringify(value, null, 2) to format it.
Python. json.loads(s) decodes a JSON string. For a double-encoded string, call it twice.
jq. jq -r . file.json prints a JSON string as raw text, and jq 'fromjson' parses a string that contains JSON.
Related tools
To go the other way and escape text into a JSON string, use JSON Stringify Text. To validate or reformat the result, use the JSON Formatter. To turn it into YAML, use the JSON to YAML Converter.