Skip to content
ToolkitHub

JSON Minifier

Minify JSON to save space

Guide

Shrinking JSON: what minification removes

By Logappradeep · ServiceNow developer

Minifying JSON means removing every character that a parser ignores, leaving the shortest valid text that represents the same data. Readable JSON is full of spaces, tabs, and line breaks used for indentation. Those bytes help humans but cost bandwidth, storage, and sometimes money when data is billed or limited by size.

What counts as removable

RFC 8259 defines exactly four insignificant whitespace characters that may appear around structural tokens like braces, brackets, colons, and commas: space, horizontal tab, line feed, and carriage return. A minifier strips those and nothing else. Whitespace inside string values is data, so it is preserved exactly:

{
  "title": "Hello  world",
  "tags": [ "a", "b" ]
}

minifies to {"title":"Hello world","tags":["a","b"]}. Note the double space inside the title survives.

Where compact JSON is useful

  • Environment variables and CLI arguments, where a value must fit on a single line.
  • JSON Lines (NDJSON) logs, which require one complete JSON document per line.
  • Browser storage and cookies, where every byte counts toward a quota.
  • Embedding data in an HTML attribute, a message queue, or a database text column.
  • Fixtures and API mocks that should stay small in a repository.

How much does it save?

It depends on how deeply nested and how heavily indented the input is. Deeply indented documents can shrink noticeably, while data dominated by long string values barely changes. Keep in mind that HTTP compression such as gzip or Brotli already squeezes out most repetitive whitespace in transit, so minification matters most where compression is not applied: storage, logs, size-limited fields, and payloads that are signed or hashed byte for byte.

Things to watch for

  • Comments are not stripped, they are rejected. JSON has no comment syntax, so files written in JSONC or JSON5 style (common in editor and TypeScript configs) fail to parse. Remove comments and trailing commas first.
  • Keep source files readable. Committing minified JSON makes diffs unreadable because the entire document is one changed line. Minify at build or send time instead.
  • Minifying also validates. Because the tool parses the input before printing it compactly, a successful result guarantees the JSON is syntactically valid.

Minification runs locally in your browser; the JSON you paste is never uploaded.

Frequently asked questions

Does minifying change any values?

No values are intentionally changed, but the JSON is parsed and re-serialized, so integers beyond 2^53 lose precision and duplicate keys keep only their last value.

Is minified JSON still valid JSON?

Yes. Whitespace between tokens is optional in the JSON grammar, so the compact form is fully valid and parses to the same data.

Should I minify JSON if my server uses gzip?

The gain over the network is usually small because gzip already compresses whitespace well. It still helps for storage, logs, and size-limited fields.

Why does my config file fail to minify?

It probably contains comments or trailing commas, which are allowed in JSONC and JSON5 but not in standard JSON.