Tool Guides ·Jul 15, 2026 ·2 min read

The Complete Guide to JSON Formatting and Validation

Pretty-print, validate and debug JSON with confidence — from the syntax rules to the most common production errors.

Daniel Osei

Software Engineer & Developer Tools

JSON is the lingua franca of APIs, and formatting it well is the difference between "works" and "works and is maintainable". This guide covers the rules, the mistakes and the workflow we use to debug JSON every day.

The syntax rules (all of them)

  • Objects use {} with "key": value pairs separated by commas.
  • Arrays use [] with values separated by commas.
  • Keys must be double-quoted strings.
  • Strings must be double-quoted; escapes use backslashes.
  • Numbers have no quotes and no leading zeros.
  • Valid values: string, number, boolean, null, array, object.
  • No comments. No trailing commas.

The five most common errors

ErrorExampleWhy it fails
Trailing comma{"a":1,}Parser expects a value after the comma
Unquoted key{a:1}Keys must be strings
Single quotes['a']JSON only accepts double quotes
Comments{/* note */}JSON has no comment syntax
NaN / undefined{"x": NaN}Only literal values are allowed

The debugging workflow

  1. Paste the JSON into the formatter and read the highlighted error location.
  2. Fix the reported issue — it is almost always at or just before the highlight.
  3. Re-format and inspect the structure with branches collapsed.
  4. Trace one path from root to a leaf to verify the data shape.
  5. Minify only when you are ready to ship.

Pretty vs minified: both are the same data

Formatting only changes whitespace. The parser sees identical values either way. Use pretty for humans and debugging, minified for payloads and storage. One click switches between them.

If the formatter passes, the JSON is valid — the tool uses a full parser, not a regex. Pass means pass.

What is the difference between JSON and JSONL?

JSONL is one JSON value per line, used for streaming and logs. The formatter handles single JSON documents; for JSONL, validate each line separately.

Tools for this task

JSON Formatter

Popular

Pretty-print, validate and minify JSON — securely in your browser.

Developer Tools Use tool

Keep reading