How to minify JSON

Minifying JSON removes extra whitespace without changing the data. It is a small optimization, but it is useful when you need a compact payload for transport, tests, or inline examples.

What minification changes

Minification removes spaces, tabs, and line breaks. A formatted object like this:

{
  "name": "Ada",
  "role": "admin"
}

becomes:

{"name":"Ada","role":"admin"}

When to minify

  • When you need a compact payload.
  • When you are embedding JSON into tests or one-line examples.
  • When you want a smaller representation for quick transport.

When not to minify

Do not minify while you are still debugging or reviewing the structure. Readable formatting is much better until the payload is stable.

FAQ

Can I minify invalid JSON?

No. The JSON must be valid first.

Does minifying make JSON faster to parse?

Its main benefit is size reduction and compactness, not a change in the meaning of the data.

Can I undo minification later?

Yes. Pretty print the valid JSON again whenever you need readability.

Should I minify while debugging?

Usually no. Keep the payload formatted until you finish debugging.