DevTools Hub
All guides

How to read messy JSON, and fix the errors it throws

Deeply nested API responses are hard to hold in your head. How to navigate JSON structurally, and what the three most common parse errors actually mean.

11 August 20262 min read

JSON is simple in principle and exhausting in practice, because real payloads arrive minified, nested five levels deep, and occasionally malformed. Two skills help: seeing the shape rather than the characters, and recognising parse errors on sight.

Look at shape before content

Every JSON document is a tree. The useful question is not what the values are but how the containers nest: is this an object of arrays, or an array of objects? That single distinction determines how you loop over it, and it is the thing minified JSON hides most effectively.

Viewing a payload as a tree makes the answer immediate. Collapse the branches you do not care about, and the structure you are actually working with fits on one screen — which is usually all you needed to write the correct access path.

The three errors you will actually hit

A trailing comma after the last item in an object or array is the most frequent. JavaScript object literals allow it, JSON does not, and the error message points at the closing brace rather than the comma — so look one line up.

Single quotes are second. JSON requires double quotes, for both strings and property names, so {'name': 'Ada'} is invalid while {"name": "Ada"} is fine. Third is unquoted property names, valid in JavaScript and invalid in JSON for the same reason.

Formatting and minifying are not edits

Formatting adds whitespace so a human can read the structure. Minifying removes every optional byte so it travels faster. Neither changes the data at all, so it is always safe to reformat a payload before reasoning about it, then minify it again before sending.

One caveat: key order is preserved by most parsers but is not guaranteed by the specification, and duplicate keys are technically allowed with the last one winning. If your data depends on either, the problem is upstream of the formatting.

In short

Read the tree, not the text. When the parser complains, check for a trailing comma, then for single quotes, then for unquoted keys — that covers almost every case.

JSON Visualizer

Format, validate, and beautify JSON data with syntax highlighting and error detection.

Open the tool

Keep reading