Start from the end state, because that is where most people meet this bug. You call JSON.parse once, you expect an object, and you get text that looks like JSON. parsed.name is undefined. typeof parsed says string. If you log it, you see \"{ everywhere, quotes wearing backslashes like a costume. One more parse would give you the object, and that tempts a lot of people into writing a parse loop that keeps going until the result stops being a string.
Do not do that as a permanent fix. It works on the data in front of you and quietly breaks on the next shape that legitimately is a string. A field that is supposed to hold a sentence will get parsed as JSON by accident, or a parse will throw halfway through a loop and take down a request that was fine a minute ago. The loop also hides the real question, which is where the second encoding happened.
How JSON gets double encoded
Encoding turns a value into text. Stringify an object once and you get text. Stringify that text again and the serializer treats it as an ordinary string, so every quote inside it gets escaped and the whole thing gets wrapped in another pair of quotes. Nothing is corrupt. The data is valid JSON, twice over. That is why the error, when there is one, shows up far from the cause: the parser is happy, and your application logic is the thing that chokes.
The usual suspects are layers that each think they own serialization. A backend returns a JSON string from a database column instead of the decoded value, and a framework serializes the response again. A frontend stores an already stringified value in localStorage, then a state library stringifies the whole state object on save. A logging or queue layer encodes a payload that was already encoded by the caller. I have seen all three in different codebases, and in each case the person debugging it started by blaming the parser, which was the one component doing its job correctly.
Here is the shape to look for. Start with {name: "Ada"}. One stringify gives you the text {"name":"Ada"}. A second gives you "{\"name\":\"Ada\"}". Parse once and you are back to text. Parse twice and you are back to the object. Count the layers in your actual payload the same way: if the first parse returns a string that itself looks like JSON, you have at least one extra layer. If it returns a string that looks like nothing, you may have a different bug, and piling on parses will only make it worse.
Fixing double encoded JSON at the source
The durable fix is a boundary rule: serialize once, at the edge, and pass values, not text, everywhere inside. In practice that means checking the type before you stringify. If the value is already a string, do not stringify it again unless you genuinely mean to send a string. If a function receives a JSON string from a database or an API, parse it once at the boundary and hand the object onward. If a framework already serializes responses, return the object and let it do its job.
For data you already have, and cannot regenerate, parse defensively but deliberately. Parse once. Check the type of the result. If it is a string and it starts with { or [, parse that string once more, and log the fact that you did, because that log entry is how the next person finds the layer that needs fixing. Cap it at two parses, in code, not in a loop. A value that needs three parses is telling you something is wrong upstream, and papering over it will cost more later than fixing the encoder now.
One more trap sits inside this one. Some APIs legitimately return a JSON string inside a field, a message body or a nested payload that the provider encoded on purpose. Parsing that field twice is correct there, because the outer object is real data and the inner string is a second document. The test is intent: if the field is documented as a string that contains JSON, parse it. If the whole response is a string that contains your object, something encoded twice by accident. Same technique, opposite diagnosis, and getting them confused is how a quick fix becomes a second bug.
There is a question I still do not have a clean answer for, and I will leave it standing rather than dress it up: when a third party API double encodes intermittently, sometimes a string and sometimes an object for the same field, how much defensive parsing is prudent and how much is just hiding a contract you should renegotiate? My own leaning is to parse the documented shape, fail loudly on the other one, and let the failures make the case for a fix. But I know teams that ship the tolerant version and never look back, and their users never notice the difference.
Paste the double encoded text into the JSON repair tool to see each layer unwrapped, then trace the layer back to the code that added it. That trace is the actual fix. The parse call is just first aid.
Try it free, right in your browser.
Frequently asked questions
How do I know if my JSON is double encoded?
Parse it once. If the result is a string that itself looks like JSON, with escaped quotes inside, it was encoded twice. If the result is an object, it was not.
Is it safe to just parse until the result is not a string?
No, not as a permanent fix. A loop can misparse a field that is legitimately a string, and it hides the encoder that added the extra layer. Parse at most twice, log the second parse, and fix the source.
Can double encoded JSON still be valid JSON?
Yes. Each encoding produces valid JSON. That is why parsers accept it and application code fails: the structure is correct, but the type is a string where an object was expected.
Where does double encoding usually happen?
At a boundary where two layers both serialize: a database column holding JSON text that a framework serializes again, a frontend that stringifies state already stored as text, or a queue or logging layer that encodes an already encoded payload.
What if an API returns a JSON string inside a field on purpose?
Then parsing that field a second time is correct. The difference is intent: a documented string field containing JSON is a nested document, while a whole response that is a string containing your object is an accidental extra layer.
Get one practical guide a week: subscribe to the newsletter.
Related reading: The trailing comma that breaks your JSON · Unescaped quotes in JSON string values · JSON with comments (JSONC)