JSON Minifier
Strip whitespace and comments from JSON.
Overview
The JSON minifier strips every byte of optional whitespace from a JSON document, producing the shortest possible serialisation that still parses. Inline comments and trailing commas — which are JSON5 extensions, not valid JSON — are also removed.
Minified JSON is the right shape for HTTP responses, embedded config in a static file, and any payload where bytes count. Developers reach for a json minifier when shrinking webhook bodies, generating compact fixtures, or auditing how much whitespace they're wasting in a config.
How it works
The minifier parses the document with a permissive front-end that tolerates JSON5 comments (// ..., /* ... */) and trailing commas, then re-emits a strict JSON form per RFC 8259. Whitespace between tokens is dropped, but whitespace inside strings is preserved exactly — that's data, not formatting.
Number formatting is normalised lightly: leading zeros are removed, + signs on positive numbers are stripped, and explicit 0 exponents are dropped. Underlying numeric values stay identical to what the source represented; this isn't lossy compression.
Examples
Input:
{
"name": "Alice",
// admin user
"age": 30,
"tags": ["admin", "ops",]
}
Output:
{"name":"Alice","age":30,"tags":["admin","ops"]}
Input: [ 1 , 2 , 3 ]
Output: [1,2,3]
Strings preserved:
Input: {"msg": "hello world"}
Output: {"msg":"hello world"}
FAQ
Will minified JSON parse in every standard library?
Yes. The output is strict JSON per RFC 8259 / ECMA-404, parseable by every conforming implementation including JSON.parse in browsers and System.Text.Json in .NET.
How much smaller is the result?
Typical reduction is 20–40% for documents with deep nesting and lots of indentation. Documents that are already compact (single-line API responses) shrink less, since there's not much whitespace to remove.
Does it remove duplicate keys?
No — that's outside the scope of minification. JSON technically allows duplicate keys, though most parsers keep only the last one. For deduplication, format the JSON and inspect it manually.