How to Format and Validate JSON (and Fix the 6 Most Common Errors)
Why JSON breaks, how to read a validator's error message, and a quick routine for pretty-printing, minifying and fixing JSON from APIs, logs and config files.
Editorial disclosure: Pyalm publishes and maintains the products and free tools discussed on this site. Regulatory statements are linked to primary sources where applicable. No independent professional review is claimed unless a reviewer is explicitly named.
JSON is the language APIs, webhooks, config files and logs use to exchange data. It is deliberately strict — and that strictness is why a single stray comma can break an integration. This guide covers how to format JSON so you can read it, how to validate it, and how to fix the errors you'll meet most often.
Format, validate, minify: what each one does
| Action | What it does | When to use it |
|---|---|---|
| Format (pretty-print) | Adds indentation and line breaks | Reading an API response, reviewing a config |
| Validate | Checks the text is legal JSON and reports the first error | Before you save a config or send a request |
| Minify | Removes all unnecessary whitespace | Storing or sending JSON as compactly as possible |
| Sort keys | Orders object keys alphabetically | Comparing two payloads by eye |
All four leave the data unchanged — only the presentation differs.
How to format JSON in three steps
- Open the free JSON Formatter & Validator.
- Paste your JSON. It is validated as you type.
- Choose 2 spaces, 4 spaces, tabs or Minify, then copy or download the result.
Everything runs in your browser, so you can safely paste responses that contain customer data or tokens.
The 6 most common JSON errors
1. Trailing commas
{"a": 1, "b": 2,} — JavaScript allows the final comma; JSON does not. Delete it.
2. Single quotes
{'name': 'Aisha'} is not JSON. Keys and strings must use double quotes: {"name": "Aisha"}.
3. Unquoted keys
{name: "Aisha"} works in JavaScript objects but not JSON. Quote every key.
4. Comments
JSON has no comments. Remove // ... and / ... /, or move notes into a "_comment" field if you must.
5. Unescaped characters in strings
A raw line break or tab inside a string is illegal. Use \n and \t. Backslashes in Windows paths need doubling: "C:\\Users".
6. Wrong value types
True, None and undefined (from Python or JavaScript) aren't JSON. Use true, false and null.
Reading a validator error
A good validator tells you the line and column of the first problem. The real mistake is often just before that position — a missing comma at the end of the previous line shows up as an "unexpected string" on the next one. Fix the first error, re-validate, and repeat; one mistake can hide others.
Tips for working with JSON every day
- Sort keys before comparing two responses by eye — or use JSON Compare to diff them structurally.
- Keep secrets out of shared JSON. Tokens in pasted payloads end up in chat logs and tickets.
- Decode JWTs and Base64 separately. Tokens inside JSON often need the JWT Decoder or Base64 decoder.
- Test the endpoint, not just the payload. The API Tester sends real requests and pretty-prints the response.
When JSON wrangling becomes a job
If your team spends hours each week reshaping JSON between systems — exporting from one app, fixing fields, importing into another — that's an integration waiting to be built. Pyalm builds custom software and integrations and business automation that move data between your tools automatically, with validation built in.
Related free tools
JSON Formatter | JSON Compare | API Tester | JWT Decoder | All free tools