← All JSON guides

JSON guide · 6 min read

JSON Escape and Unescape: Quotes, Backslashes and Newlines

Escape JSON for string literals and logs, decode escaped content and avoid confusing a JSON document with a JSON-encoded string.

Published 2026-08-05Reviewed 2026-08-05

Why escaping is needed

A JSON string uses quotes and backslashes as syntax. When an entire JSON document is embedded inside another string, those characters must be escaped for the outer layer.

Document versus encoded string

The text {"name":"Ada"} is a JSON object document. The text "{\"name\":\"Ada\"}" is a JSON string whose value contains serialized JSON.

Common escape sequences

The visual result depends on whether you are viewing source text or the decoded value.

  • \" represents a quote inside a string.
  • \\ represents a literal backslash.
  • \n represents a newline character.
  • \t represents a tab.

Avoid repeated encoding

Each unnecessary serialization layer adds backslashes. Track which component owns parsing and serialization, and decode only the layer you intend to remove.

Common questions

Frequently asked questions

Why does my JSON contain many backslashes?

It is probably serialized inside another string or has been encoded more than once.

Does unescaping automatically parse the JSON object?

Not necessarily. Unescaping may return JSON text that still needs syntax validation and parsing.