Skip to main content

Guides

How to Format, Validate, and Debug JSON (Common Parse Errors Explained)

Vibeus Moonscript

Vibeus Moonscript

December 9, 2025

How to Format, Validate, and Debug JSON (Common Parse Errors Explained)

Most APIs don’t send you pretty JSON. They send you one long line with no spaces, no line breaks, and no mercy. That’s fine for machines. For humans trying to figure out why a key is missing or what the response structure actually looks like, it’s a problem.

A JSON formatter takes that line and turns it into something readable: indented, structured, visually organized. It doesn’t change the data, just adds whitespace. A good one also tells you the key count, line count, and byte size, which matters more than you’d expect when comparing a formatted payload against its minified version.

Skip ahead and format your JSON now.

When JSON won’t parse

A parse error means the JSON is malformed. The browser’s JSON parser hit something it couldn’t interpret and stopped. The most common causes:

Trailing commas. JSON doesn’t allow a comma after the last item in an object or array. JavaScript objects and most modern languages tolerate it. JSON does not.

// Invalid
{
  "name": "Alice",
  "role": "admin",
}

// Valid
{
  "name": "Alice",
  "role": "admin"
}

Single quotes. JSON requires double quotes for both property keys and string values. Single quotes aren’t valid, even though JavaScript objects accept them.

// Invalid
{'name': 'Alice'}

// Valid
{"name": "Alice"}

Unquoted keys. In a JavaScript object literal you can write {name: "Alice"}. In JSON you can’t. All keys must be quoted strings.

Comments. JSON has no comment syntax. // this is a comment will break the parse. If you’re maintaining a config file that needs comments, look at JSON5 or JSONC formats instead of standard JSON.

Unclosed brackets or strings. Usually the result of manually editing JSON. Easy to miss when the file is long.

The error message from a JSON parser always includes a position — something like “Unexpected token at line 4, column 12”. That position points to where the parser gave up, which is usually the problem itself or the character right before it.

Format vs. minify vs. validate

These are three distinct operations, and all three are useful at different times.

Format adds indentation and line breaks. Use it when you’re reading an API response, debugging, or reviewing someone else’s config. Two-space or four-space indentation is a matter of preference — either is fine.

Minify removes all whitespace to produce the smallest valid JSON string. Use it for API payloads, test fixtures committed to version control, or config files where whitespace is pure overhead. Minified JSON also produces cleaner diffs because there’s no indentation to change when a value changes.

Validate does a strict parse check and tells you yes or no with a position. Use it when you just need to confirm something will parse — you don’t need to read it, just verify it’s valid before sending it or checking it in.

A format tool does the first, but a good one combines all three in the same interface so you don’t need different tabs for different operations.

The byte size detail

Most formatters ignore the byte size. It’s worth paying attention to. A formatted 2,000-line API response might be 85KB. Minified, it’s 30KB. That delta matters for API payloads, particularly in mobile contexts or when you’re close to a server’s size limit.

Byte size also helps debug 413 Payload Too Large errors — you can see immediately whether the request body is actually over the limit before investigating anything else.

Practical workflow

Paste the raw response, click format, read the structure. If you’re debugging a validation error, the error message with exact position saves you from scanning manually. If you need to commit or send the JSON, minify before copying.

If you work with API responses regularly, keeping a formatter open as a permanent tab is faster than running JSON.stringify(JSON.parse(data), null, 2) in a console each time.

What makes a good online JSON formatter

Privacy matters more than most people consider. When you paste an API response into a random tool, you often don’t know whether it’s processed client-side or sent to their server. For anything containing API keys, tokens, user data, or internal config, you want client-side processing.

Beyond that: precise error messages (line and column, not just “invalid JSON”), minify and validate alongside format, and byte size output. Those are the details that make the difference in actual use.

Format, minify, or validate your JSON. Runs entirely in your browser — nothing is sent to a server.