DevLab
{}
JSONbeginner

JSON Minifier

minify JSON by removing whitespace to reduce size

By Bikram NathLast updated

Strips all whitespace characters (spaces, tabs, and newlines) from JSON to produce the smallest valid representation of the data. Paste a formatted API response like { "id": 1, "name": "Alice" } and get {"id":1,"name":"Alice"} back. Unlike a formatter that also validates structure, this tool focuses purely on compaction without reordering keys or re-encoding numeric values.

Try it now — free, instant, no signup

What is JSON Minifier?

JSON Minifier takes a JSON document and removes every whitespace character that is not inside a string value. A 4KB pretty-printed config file with two-space indentation typically compresses to under 1KB after minification, leaving just key-value pairs with no padding. The output is semantically identical to the input; any JSON parser sees the same data structure either way.

Reach for this when you need a quick result without installing anything. If you are already in a terminal, jq -c '.' does the same thing and handles arbitrarily large files. Python's json module needs json.dumps(data, separators=(',', ':')) for true minification since the default format includes a space after each colon. Where this tool wins is speed of access: no shell, no module import, no flags to remember, making it useful mid-debugging when you need to paste a compact payload into a curl command or a test fixture.

One gotcha: whitespace inside string values is never touched. If your JSON contains "address": "123 Main St " with trailing spaces inside the value, those spaces survive minification intact. This is correct behavior per spec, but it surprises people expecting a broadly clean output. Separately, if your source includes C-style // or /* */ comments, which are a JSON5 extension and not valid ECMA-404, the parser will reject the entire document before minification begins.

When to use JSON Minifier

Reduce a formatted API response before embedding it as a test fixture in source code to avoid noisy diffs.
Compare two JSON payloads byte-by-byte after minification to isolate whether differences are structural or just formatting.
Prepare a compact JSON config string for an environment variable where embedded newlines would break shell parsing.

Frequently Asked Questions

Does minifying change key order or alter how numbers are encoded?
Key order is preserved. The browser's JSON.parse followed by JSON.stringify maintains insertion order for string keys as of ECMAScript 2015. Numbers, however, are re-serialized by the JavaScript engine, so 1.0 becomes 1 and 1.000e3 becomes 1000, both mathematically identical but different byte sequences. If exact byte-for-byte preservation of the original number representation matters, that is a sign minification is the wrong step for your use case.
My source JSON has // comments and the tool rejects it. Why?
Standard JSON (ECMA-404) does not allow comments. The tool processes valid JSON only, so C-style // and /* */ comments, which are a JSON5 extension, cause a parse failure before minification begins. This is a spec constraint, not a tool limitation. Strip comments first with a sed command like sed 's|//[^"]*$||g' or run the file through a JSON5-aware parser such as the json5 npm package, then paste the clean output here.
Is there a practical file-size limit for minifying JSON in the browser?
The theoretical ceiling is V8's string size limit, roughly 512MB on 64-bit systems, but browser tab memory pressure becomes noticeable well before that. Files above 50MB will cause visible pausing and occasional tab crashes depending on available RAM. For anything over 20MB, jq -c '.' input.json > output.json in a terminal is faster and more reliable. This tool is optimized for the common case of API responses and config snippets, not bulk data processing.
How much smaller does JSON actually get after minification?
It depends on indentation depth and nesting level. A file formatted with 4-space indentation and deeply nested objects typically shrinks 30 to 50 percent by byte count. Shallow, single-level objects with short keys might only shrink 10 to 15 percent. Minification also makes gzip and Brotli compression marginally more predictable, since the repetitive whitespace patterns being removed are patterns those compressors already absorbed cheaply at the cost of slightly longer compression time.
Can I minify JSON that is embedded inside a JavaScript or TypeScript file?
Not directly. The tool expects a raw JSON document as input, not a JS variable assignment like const config = { ... } or an object literal inside a TypeScript module. Extract just the JSON object or array, minify it here, then paste the compact string back. If the JSON lives inside a JS module as an object literal rather than a quoted string, build tools like esbuild or Terser will compact it as part of their normal minification pass without any manual extraction needed.

Related Tools