🍋
Menu
How-To Beginner 1 min read 175 words

How to Format and Validate JSON Data

Minified JSON is unreadable and errors are hard to find. Learn how to pretty-print, validate, and transform JSON for debugging and development.

Key Takeaways

  • API responses and configuration files often arrive as single-line minified JSON.
  • JSON syntax is strict — a single missing comma or extra bracket breaks the entire document.
  • Trailing commas**: `{"a": 1,}` — not allowed in JSON (allowed in JS).
  • JSON5 and JSONC are supersets that allow comments, trailing commas, and single quotes.
  • The reverse of pretty-printing — removing whitespace to minimize file size.

Why Format JSON?

API responses and configuration files often arrive as single-line minified JSON. Pretty-printing adds indentation and line breaks, making the structure visible and errors easy to spot.

Validation

JSON syntax is strict — a single missing comma or extra bracket breaks the entire document. Validators highlight the exact line and character where parsing fails, saving debugging time.

Common JSON Errors

  • Trailing commas: {"a": 1,} — not allowed in JSON (allowed in JS).
  • Single quotes: {'key': 'value'}JSON requires double quotes.
  • Unquoted keys: {key: "value"} — keys must be quoted strings.
  • Comments: // commentJSON doesn't support comments.

JSON vs JSON5 vs JSONC

JSON5 and JSONC are supersets that allow comments, trailing commas, and single quotes. They're used in configuration files (tsconfig.json, VS Code settings) but aren't valid JSON for APIs.

Minification

The reverse of pretty-printing — removing whitespace to minimize file size. Minified JSON is 30-50% smaller than pretty-printed, making it ideal for API responses and storage where human readability isn't needed.

Outils associés

Formats associés

Guides associés