If you build anything that talks to an API, you live in JSON. It is the format that carries data between servers, browsers, mobile apps, and configuration files. It is simple by design, which is exactly why a single stray comma or missing quote can bring an entire request crashing down with a cryptic error. Knowing how to format, validate, and debug JSON quickly is a core developer skill.
What JSON Is and Why It Won
JSON (JavaScript Object Notation) is a lightweight, text-based format for structured data. It won out over heavier formats because it is human-readable, maps cleanly to data structures in nearly every language, and is trivial for machines to parse. A JSON document is built from a few simple pieces:
- Objects — key/value pairs wrapped in curly braces:
{ "name": "Ada" } - Arrays — ordered lists in square brackets:
[1, 2, 3] - Values — strings, numbers, booleans,
null, objects, or arrays - Strings — always in double quotes
That simplicity is its strength, but the strict rules trip people up constantly.
The Syntax Rules That Actually Matter
Most JSON errors come from breaking one of these:
- Double quotes only. Keys and string values must use double quotes, never single quotes.
- No trailing commas.
[1, 2, 3,]is invalid. The last item cannot be followed by a comma. - Keys must be quoted.
{ name: "Ada" }is invalid; it must be{ "name": "Ada" }. - No comments. Plain JSON does not support
//or/* */. - Proper nesting. Every
{needs a}and every[needs a], correctly matched.
Tip:
NaN,Infinity, andundefinedare not valid JSON values. If your data contains them, you will get a parse error. Convert them tonullor a string first.
Step-by-Step: Format and Validate JSON
Use the JSON Formatter, which parses and formats entirely in your browser.
- Paste your JSON. Drop in the raw response or config text.
- Format it. Click to beautify with 2- or 4-space indentation. The nested structure becomes instantly readable.
- Read any error. If the JSON is invalid, the tool reports what went wrong and roughly where, so you can jump straight to the problem.
- Fix and re-check. Correct the issue — usually a comma or quote — and format again.
- Minify when shipping. For production payloads, minify to strip whitespace and reduce size.
For a pass/fail check without reformatting, the dedicated JSON Validator confirms whether your JSON is well-formed.
Formatting vs. Minifying
These are two directions of the same operation:
| Operation | What it does | When to use |
|---|---|---|
| Format / beautify | Adds indentation and line breaks | Reading, debugging, code review |
| Minify | Removes all whitespace | API responses, storage, transfer |
During development you format to read; before shipping you minify to shrink. A good tool does both.
Debugging JSON Fast
When JSON will not parse, work through this quick checklist:
- Check the ends. Confirm the document opens and closes with matching braces or brackets.
- Hunt for trailing commas. Look at the last item in every object and array.
- Scan the quotes. Make sure every key and string uses double quotes and that none are unclosed.
- Watch for stray characters. A copied response sometimes includes leading text, a byte-order mark, or HTML wrapping.
- Compare versions. If it worked before and broke now, run both through a diff checker to spot the change.
Best Practices for Working with JSON
- Format API responses while debugging. A wall of minified JSON hides the structure; beautify it to understand the shape of the data.
- Validate before sending. Catch malformed request bodies locally instead of chasing a 400 error from the server.
- Keep sensitive data local. API responses often carry tokens and personal data. Use a browser-based tool so nothing is uploaded.
- Mind number precision. Very large integers can lose precision when parsed as floating point. Store them as strings if exactness matters.
Common Mistakes to Avoid
- Single quotes. JavaScript accepts them; JSON does not.
- Trailing commas. The most frequent JSON error by far.
- Comments. They belong in code, not in JSON data.
- Pasting into a server-side formatter. For anything sensitive, keep it in the browser.
Conclusion
JSON is simple, but its strictness is unforgiving — most "broken API" moments trace back to a comma, a quote, or a bracket. Format your JSON to read it, validate to confirm it parses, minify to ship it, and keep a mental checklist for the handful of errors that cause 90% of problems. With a fast, private tool at hand, JSON debugging goes from frustrating to trivial.
Format and validate your JSON now with the free JSON Formatter — instant, private, and always in your browser.