Same data, opposite presentations

JSON validators, formatters, and minifiers all operate on the same underlying data - they only change the arrangement of whitespace. A formatter (pretty-print) adds indentation and line breaks so people can read nested structures. A minifier strips all insignificant whitespace so the payload takes as little space as possible. Both leave the data value-for-value identical.

What a formatter does

Formatting turns a single-line API response into a readable tree with nested objects indented beneath their parents. That is the standard way to inspect what a service actually returned. Because the structure is explicit, formatting also exposes syntax mistakes: an extra comma, an unclosed brace, or a stray quote becomes visible the instant indentation breaks.

What a minifier does

Minifying produces {"a":1,"b":2} from its formatted friend. Its size difference matters when JSON crosses a network boundary - response bodies, config files, and cached storage all shrink. It is also the form most databases and APIs prefer, since exponent whitespace competes for nothing useful.

Choose by what you are doing

  • Debugging or hand-editing? Always format first; readable structure will save you hours.
  • Shipping the payload or storing it? Minify, and let a formatter re-expand it on the client when a human needs to look.
  • Validating user-generated JSON? Format it so the error message points at a visible location.

Two things that are not JSON

Be careful with input that looks like JSON but is not: JSON with trailing commas, single-quoted strings, JavaScript object literals, and comments are all invalid. A strict validator will reject them with a position-based error - use that error to fix the source rather than assuming the formatter silently repaired it.

Keep the original safe

Formatting is lossless for data but destructive for readability inversions: once minified, reformatting restores structure only if the input was valid. Always keep the readable, canonical copy in your repo and minify as a build step, never by overwriting the source.