Skip to content

Minify JSON

Remove insignificant whitespace so JSON is compact for transport or paste limits.

What this does

Minify is the write path: one line, no pretty indent. Use it when a platform counts characters (feature flags, SSM parameters, chat paste limits) or when you want a compact fixture. It is the inverse of pretty print.

Searching “minify JSON” should not land on a beautify-first tutorial. This page leads with minify and warns when you should not minify (secrets in URLs, unreadable diffs).

People hitting “value too long” on a JSON field, or building fixtures for tests.

Minify is for machines and for fields that hate newlines. It is a hostile format for pull requests.

Character limits on vendor consoles are why this search exists. If you are under the cap already, pretty print is kinder to the next human.

Parameter stores, feature-flag consoles, and some HTTP headers treat a newline as “end of value.” Pretty JSON silently breaks those fields. Minify, then if the shell still complains, you have an escaping problem, not a whitespace problem.

Keep the pretty version in git. Generate the minified string at the boundary: a deploy script, a console paste, a test helper. If someone commits a 4,000-character single line, the next diff is unreadable and the next incident takes longer.

When to use it

  • An env var has a max length.
  • You need a single-line JSON for a CLI flag.
  • A logger truncates multiline bodies.

How to

  1. Paste valid JSON. No comments, no trailing commas.
  2. Minify. Copy the single line.
  3. Escape for the shell if needed. Minify is not shell-escaping.
  4. Store. Prefer a secret manager over a chat log.

Features

  • One-click minify. Same formatter, minify action.
  • Stats. See that the byte count actually dropped.
  • Local. Do not paste production PII into a random cloud formatter if you can avoid it — this one stays in-tab.

Why it helps

  • Fits the field. Character caps are real.
  • Fewer accidental newlines. Shell-safe single line.

Use cases

  • Feature-flag JSON. Dashboards often paste compact JSON.
  • Test fixtures over the wire. Golden files can stay pretty; the request body minified.

Examples

  • Indented config to one line. Beautified 40-line object → one line for an AWS parameter (watch the 4KB/8KB caps).

Common mistakes

  • Minifying, then committing to git where diffs become unreadable. Keep pretty in source, minify in build.
  • Minifying JSON that is actually JavaScript with comments. Comments are not valid JSON.

Tips

  • Pretty in the repo, minify at the boundary.
  • If minify fails, validate first.

FAQ

Does minify change values?
It should not. It only removes insignificant whitespace. Number formatting follows JSON.stringify rules.
Can I minify JSONC?
No. Strip comments first.