Unescape and decode stringified JSON

How unescaping stringified JSON works, what it changes and what it can silently alter, and when to keep the escaped form or plain text instead.

Stringified JSON is JSON text that has been wrapped inside a JSON string, so every inner quote and backslash carries an extra escape. It often shows up in log lines, message-queue payloads, database columns and API fields that were serialized twice. Unescaping it, sometimes called unstringifying or de-stringifying, turns that wall of backslashes back into readable JSON. This review covers what the operation changes, what it can alter without warning, and when the escaped or plain-text form is the better choice.

Is unescaping the right step for your task?

For reading, debugging or editing a payload that was serialized twice, unescaping is usually the right move. The main benefit is legibility: nested quotes, line breaks and non-ASCII characters appear as themselves rather than as escape sequences. The decisive tradeoff comes when you go further and parse the result into a data structure, then re-serialize it. That round trip can change number precision, key order, whitespace and escape style, so the output may be equivalent JSON without being byte-identical to what the producer sent.

Keep the original escaped text when the exact bytes matter. That includes signature or hash verification, reproducing a bug report, filing evidence, or passing the value back to a system that expects a string field. If the goal is only to show someone the content, such as in a ticket, chat message or document, a decoded and pretty-printed copy is easier to read. Label it as a decoded view so nobody pastes it back where the escaped string belongs.

What unescaping actually changes

JSON strings use a small set of escapes: " for a quote, \ for a backslash, / for a slash, \b, \f, \n, \r and \t for control characters, and \uXXXX for any UTF-16 code unit. When a JSON document is stringified, its own quotes and backslashes get escaped again. Decoding one layer reverses exactly that: escape sequences become the characters they stand for, and the outer quotes go away. This is a change to the stored characters, not just to how they look. The decoded text is a different, shorter sequence of code points.

There are two separate steps here, and they are easy to confuse. The first decode turns a JSON string into its contents, which for stringified JSON is itself JSON text. A second parse turns that text into an actual object or array. Many tools that say they unescape JSON do both steps and then pretty-print. Pretty-printing is a third step that only adds indentation and line breaks between tokens, and it never touches the content of string values.

Escaped (stringified) input:
"{\"user\":\"Zo\\u00eb\",\"note\":\"line 1\\nline 2\"}"

After one decode (JSON text, still a string in your program):
{"user":"Zo\u00eb","note":"line 1\nline 2"}

After a second parse (a real object):
user -> Zoë
note -> "line 1", a newline, then "line 2"

In this example the doubled backslash before u00eb becomes a single one after the first decode. Only the second parse turns it into the letter ë. The same applies to the newline. Payloads that were stringified more than twice need one decode per layer. A practical rule is to keep parsing while the result is still a string that looks like JSON, and stop at the first object, array, number, boolean or null.

// JavaScript: raw holds the text including its outer quotes
const once = JSON.parse(raw);
const value = typeof once === "string" ? JSON.parse(once) : once;
console.log(JSON.stringify(value, null, 2));

# Python
import json
once = json.loads(raw)
value = json.loads(once) if isinstance(once, str) else once
print(json.dumps(value, indent=2, ensure_ascii=False))

# jq: input.txt holds the quoted string
jq 'fromjson' input.txt   # decode and parse
jq -r '.' input.txt       # print the inner text only

Avoid doing this with find-and-replace or a regular expression that swaps " for a quote. A real parser handles escaped backslashes that come right before a quote, \u sequences and surrogate pairs in one pass. A naive replacement handles them in the wrong order and can corrupt the text without any error.

Operations with similar names

Operation | What it decodes | Example
JSON string unescape | JSON escape sequences inside a quoted string | " becomes a quote, \u00e9 becomes é
JavaScript's legacy unescape() function | Percent-style escapes, not JSON | %20 becomes a space
URL decoding | Percent-encoded bytes in URLs and form data | %22 becomes a quote
HTML entity decoding | Named and numeric character references | " becomes a quote
Base64 decoding | Binary-to-text encoding | Output may be JSON, but the escaping is a different layer
Pretty-printing | Nothing; only whitespace between tokens is added | Content of strings is unchanged

Searches for unescaping JSON sometimes land on JavaScript's global unescape() function. That function is deprecated and handles percent encoding, so it will not decode JSON escapes correctly. If the input contains percent signs or ampersand entities instead of backslashes, it needs a different decoder, applied before the JSON step.

Changes that can happen silently

  • Large integers: JavaScript parses JSON numbers as double-precision floats, so 9007199254740993 becomes 9007199254740992. Python keeps arbitrary-precision integers, so results differ between environments.
  • Key order: when a JavaScript object is re-serialized, integer-like keys come first in ascending order. {"b":1,"2":2,"1":3} comes back as {"1":3,"2":2,"b":1}.
  • Duplicate keys: the JSON specification does not require parsers to reject them. Many keep only the last value, so data can disappear on the round trip.
  • Escape style: \u00e9 may come back as é, and / as a plain slash. That is equivalent JSON but different bytes.
  • Whitespace and formatting inside the original JSON are replaced by whatever the serializer produces.

Emoji, combining marks and invalid surrogates

Characters outside the Basic Multilingual Plane are escaped as two \u sequences, a surrogate pair. For example, \ud83d\ude00 decodes to a single grinning-face emoji. Some characters that look like one symbol are several code points. Flag emoji, skin-tone variants and letters with separate combining accents all fall into this group. Decoding keeps them intact because it does not reorder anything. They only break if a later step truncates or reverses the string by code unit.

JSON syntax allows a lone surrogate such as \ud83d with no partner, even though that is not valid Unicode text. JavaScript's JSON.parse accepts it. Python's json.loads accepts it too, but encoding the result to UTF-8 then raises an error. Other parsers may reject it or substitute a replacement character. If decoding fails at that stage, a lone surrogate in the source is a likely cause.

Will the result stay readable and usable after copying or sharing?

The decoded form is easier for people to read. It is also more fragile to move around than the escaped form, because it now contains literal quotes, newlines and possibly invisible characters. Most of the problems below come from the move itself, not from the decode.

  • Outer quotes: a single decode expects the leading and trailing quote. Values copied from a log viewer or a debugger panel often lose them, and the parse then fails or treats the text as already-unescaped JSON.
  • Shell quoting: in a terminal, double-quoted arguments and commands such as echo -e may interpret backslashes before your tool sees them. Reading from a file or using single quotes avoids that.
  • Not actually JSON: output from a language's debug print, with single quotes, True, None or trailing commas, looks similar but will not parse as JSON. It needs a converter for that language's syntax.
  • Pasting back into code: decoded JSON placed inside a string literal in source code must be escaped again for that language, or the quotes will end the literal early.

Invisible and directional characters need extra care. An escape such as \u200b becomes a zero-width space you cannot see. \u202e becomes a right-to-left override that visually reverses the text after it while leaving the stored character order unchanged. In the escaped form these are obvious. After decoding, a value can look different from what it contains, which matters for code review, security checks and comparing identifiers. Tools that show hidden or bidirectional control characters, or a quick look back at the escaped source, settle any doubt.

For accessibility, escaped strings are dense with backslashes and are likely to be tedious when read aloud. A decoded, indented version generally gives assistive technology more natural structure to work with. No screen reader or editor was tested for this review, so this is a general expectation, not a verified result. When the content is shared with non-developers, a plain-text summary of the relevant fields usually serves them better than either JSON form.

Choosing a tool and gaps in this review

No evidence about specific online unescape tools was available, so this review makes no claims about their accuracy, limits or features. A tool's appearance or marketing says nothing reliable about whether it uploads, logs or keeps what you paste. For tokens, personal data or production payloads, decoding locally with a language's built-in JSON parser or jq avoids that question entirely. The precision, key-order and surrogate behaviors described above follow from documented parser behavior in JavaScript and Python. Other languages and libraries may differ and are worth checking against a sample that contains large numbers, numeric keys and non-ASCII text before relying on them.