Z

How to Format JSON (Beautify, Validate & Minify)

Zerethon · 2 min read

Minified or hand-edited JSON is hard to read and easy to break. Formatting (or "beautifying") it adds consistent indentation and line breaks so you can scan the structure, spot errors, and diff changes. Here is how to do it quickly and safely.

What "formatting JSON" means

Formatting only changes whitespace — indentation and line breaks — never the data. A formatter parses your JSON into a tree and re-serialises it with consistent spacing, which also surfaces syntax errors (a missing comma or bracket fails to parse).

Step 1 — Paste your JSON

Open the JSON Formatter and paste your JSON into the input. It runs entirely in your browser, so even sensitive payloads never leave your device.

Step 2 — Beautify

The formatter re-indents the document (typically 2 spaces). Nested objects and arrays become a readable tree. If the JSON is invalid, you get an error pointing at the problem instead of formatted output — a fast way to validate.

Step 3 — Validate as you go

Because formatting requires parsing, a successful format is a validity check. For stricter checks (trailing commas, comments, schema), use a dedicated validator — but for everyday "is this valid JSON?", formatting answers it instantly.

Step 4 — Minify for production

When shipping JSON in an API response or config bundle, minify it — strip all whitespace to shrink the payload. Most formatters offer a "minify" toggle that reverses the beautify step.

Common mistakes

  • Trailing commas — valid in JavaScript objects, invalid in JSON.
  • Single quotes — JSON requires double quotes for strings and keys.
  • Comments — JSON has none; use JSON5 or YAML if you need them (see JSON vs YAML).

Next steps

JSON Formatting Developers