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.