All articles
DeveloperJSONJul 22, 2026 · 5 min read

How to Format & Fix JSON (Common Errors)

JSON is everywhere — API responses, config files, logs — but a single misplaced comma can break it. This guide covers how to format JSON so it's readable, how to minify it for production, and how to fix the errors you'll actually run into.

Format (beautify) vs. minify

Formatting (or beautifying) adds consistent indentation and line breaks so JSON is easy to read and diff. Minifying strips all whitespace to produce the smallest valid payload — ideal for sending over the wire. You want formatted JSON while developing and minified JSON in production.

The fastest way to do either is our JSON formatter — paste your JSON, click Format or Minify, and it validates as it goes. Everything runs in your browser, so even sensitive payloads stay on your device.

The most common JSON errors

1. Trailing commas

JSON does not allow a comma after the last item. {"a": 1,} is invalid — remove the trailing comma to get {"a": 1}.

2. Single quotes

JSON strings and keys must use double quotes. {'a': 1} is invalid; it must be {"a": 1}.

3. Unquoted keys

Unlike JavaScript objects, JSON keys are always quoted. {a: 1} is invalid — write {"a": 1}.

4. Missing or extra commas

Every item except the last needs a comma between them. A validator points to the exact position of the problem, which is far faster than hunting by eye.

5. Comments

Standard JSON does not support // or /* */ comments. Remove them, or use a format like JSON5 if your tooling supports it.

Validate before you ship

A quick validation step catches these before they cause a runtime error. Paste your JSON into the formatter; if it's invalid, you'll get the exact error and location.

Turn JSON into something else

Once your JSON is valid, you can convert it: generate TypeScript types from a sample response, or export it to CSV for a spreadsheet.

FAQ

Why is my JSON invalid when it looks fine?

The usual culprits are a trailing comma, single quotes, or an unquoted key. A validator will point to the exact character.

Does formatting change my data?

No — formatting and minifying only change whitespace, never the values themselves.