JSON fundamentals

How to fix escaped JSON strings and nested JSON text

Recognize JSON stored inside a string, remove one correct escape layer, and avoid damaging valid backslashes.

10 min read Reviewed July 19, 2026 Professional reference

Document summary

Examples and a safe workflow for API fields, logs, database exports, and double-encoded JSON.

Key takeaways

  • Use strict, representative input before relying on output.
  • Review structure, types, and edge cases instead of checking only visual formatting.
  • Continue examples inside the connected Bacodev tool to verify the result.
01

Recognize an encoded JSON string

A JSON object begins with a brace. An encoded JSON string often begins with a quote and contains escaped quotation marks such as \"name\".

02

Decode one layer at a time

  1. 1

    Parse the outer JSON value.

  2. 2

    Confirm the result is a string.

  3. 3

    Inspect whether the string contains JSON text.

  4. 4

    Parse the inner text separately.

  5. 5

    Do not repeatedly unescape arbitrary backslashes.

03

Compare object and encoded string

Invalid
"{\"name\":\"Report\"}"
Valid
{"name":"Report"}
04

Common sources of escaped JSON

  • Message queue payload fields
  • Log files
  • CSV exports
  • Database text columns
  • Command-line arguments
  • Nested API envelopes
05

Preserve legitimate escapes

06

The escape sequences strict JSON accepts

Inside a JSON string, the backslash starts an escape sequence. The full set is: \" for a quote, \\ for a backslash, \/ for a slash, \b backspace, \f form feed, \n newline, \r carriage return, \t tab, and \uXXXX for any Unicode code point.

Anything else after a backslash, such as \x or \e, is invalid strict JSON and will fail validation.

07

Spotting double-escaped JSON text

A double-escaped string has its backslashes escaped again, which happens when JSON is embedded inside another JSON string, a log line, or a database field. The text shows literal \n instead of a newline and \" instead of a quote.

The JSON repair tool detects this pattern and converts the escaped text into real JSON, and the JSON formatter re-validates the result.

Invalid
{
  "message": "Line1\\nLine2"
}
Valid
{
  "message": "Line1\nLine2"
}
08

Frequently asked questions

What does a double-escaped JSON string look like?

It contains literal backslash sequences such as \\n or \\" in the raw text, so the file shows two backslashes before the letter when it should show one.

Is \uXXXX valid in JSON?

Yes. \u followed by four hex digits is the standard escape for Unicode code points and is valid anywhere in a JSON string.

Can the tool unescape my string safely?

The repairer applies only standard JSON escape rules and reports each change, so the unescaping is predictable and reversible from the change list.

Why does my parser reject a backslash before a letter?

Strict JSON only allows the escape sequences listed above. A backslash before any other character, such as \d or \s, is a syntax error.

Jump to tool

Apply this workflow in the Json Repair tool

Open tool