JSON guide
JSON escape vs unescape
Escaped JSON is usually text inside another JSON string. Unescaping removes one string layer so the real value can be formatted or validated.
Why escaped JSON is hard to read
Logs, queues, databases, and API wrappers often store a JSON object as a string. Quotes become backslash-quote sequences, newlines become \n, and the value is visually noisy even when the outer JSON is valid.
Example
"{\"status\":\"ok\",\"count\":2}"
{"status":"ok","count":2} can be decoded from the string layer, then formatted as normal JSON.
How to handle escaped JSON
- First check whether the whole value is a valid JSON string, including the outer quotes.
- Let a JSON parser decode that string layer instead of deleting backslashes by hand.
- Format or validate the decoded inner value if it is itself JSON.
- Repeat carefully only when the data has more than one intentional encoding layer.
A practical debugging rule
If the value starts and ends with quotes and contains many backslash-quote sequences, you are probably looking at JSON stored as a string. Decode the string layer first, then inspect the inner value.
If the value starts with an object brace but contains escaped quotes only inside specific fields, the whole object may already be valid JSON. In that case, format the object first and inspect the field that contains the escaped text.
Common mistakes
- Removing every backslash manually and accidentally changing the data
- Trying to format the escaped string as if it were already an object
- Forgetting that \n represents a newline inside a string
- Unescaping twice when only one layer was encoded
Related problems
FAQ
Is escaped JSON invalid?
No. Escaped JSON can be valid as a string, but it is not the object you probably want to inspect yet.
Should I remove backslashes manually?
No. Use a parser to decode the string layer so quotes, Unicode escapes, and newlines are handled correctly.
Why do logs escape JSON?
Logs often store structured data inside a text field, so quotes and line breaks must be escaped to keep the outer record valid.