Developer guides
How to Format and Validate JSON (and Fix Common Errors)
Updated 25 September 2026 · 4 min read
JSON is strict: one stray comma and an API rejects the whole request. A formatter makes JSON readable and a validator tells you exactly where it breaks.
Format and validate JSON in your browserFormat, beautify, validate and minify JSON with clear error locations. Runs in your browser.Beautify vs minify
Beautify indents nested objects (2 or 4 spaces) so you can read and review them. Minify strips every unnecessary space for the smallest payload. Sorting keys alphabetically makes two versions easy to compare.
The 6 errors behind most invalid JSON
| Invalid | Valid | Why |
|---|---|---|
{"a": 1,} | {"a": 1} | No trailing commas |
{'a': 'x'} | {"a": "x"} | Only double quotes |
{a: 1} | {"a": 1} | Keys must be quoted |
{"a": 1 // note} | {"a": 1} | No comments |
{"a": undefined} | {"a": null} | No undefined, NaN or Infinity |
{"price": 01.50} | {"price": 1.5} | No leading zeros |
Tips
- Copying from a JavaScript object? That's where single quotes, unquoted keys and trailing commas come from.
- Large numbers like IDs above 9,007,199,254,740,991 lose precision in JavaScript — send them as strings.
- Validate API responses and config files before committing them; the error position saves minutes of hunting.
Frequently asked questions
Why is my JSON invalid?
The most common causes are a trailing comma after the last item, single quotes instead of double quotes, unquoted keys, comments, and values like undefined or NaN. A validator shows the exact line and column.
What is the difference between beautify and minify?
Beautify adds indentation and line breaks so people can read it. Minify removes all unnecessary spaces to make it as small as possible for sending over a network.
