HomeFormattersCodeJSON Minifier

JSON Minifier

Code

Minify JSON by stripping all whitespace and formatting. Optionally sort keys alphabetically. Runs entirely in your browser — nothing is uploaded anywhere.

Reviewed by the thecalcu.com team · Last updated July 13, 2026

What is a JSON Min?

The JSON Minifier strips all non-essential whitespace from a JSON document, spaces, tabs, newlines, and carriage returns that are not part of a string value, producing the smallest valid JSON representation of the same data. It is the counterpart to the JSON Formatter: where the formatter makes JSON human-readable, the minifier makes it as compact as possible for transmission and storage.

JSON is a text-based format, and pretty-printed JSON is deliberately verbose. A response like:

{
  "status": "ok",
  "count": 3
}

becomes {"status":"ok","count":3} when minified, roughly 40% smaller. For large API responses with hundreds of fields and nested objects, the savings compound significantly, reducing payload size by 20–60% depending on the depth and variety of the data.

The JSON Minifier also includes an optional key-sorting step. Sorting object keys alphabetically produces a canonical form of the JSON, two documents with the same data but different key orders produce identical minified output, which is essential for caching, comparison, and deterministic signing.

All processing runs entirely in your browser using the built-in JSON.parse() and JSON.stringify() functions. Your JSON is never sent to a server or stored anywhere, safe for API tokens, credentials, database schemas, and internal configuration.

Why Use a JSON Minifier?

The primary reason to minify JSON is to reduce network payload size. REST APIs that return large collections, configuration endpoints, or search result sets can grow to hundreds of kilobytes when pretty-printed. A minified payload transmits faster and costs less in bandwidth, particularly relevant for mobile APIs, pay-per-GB cloud egress, and high-throughput services handling millions of requests per day.

A secondary use is deterministic output for caching and comparison. If two systems independently construct the same JSON object but in different key orders, a naive comparison fails even though the data is identical. Minifying with key sorting produces a canonical form that is identical in both cases.

JSON minification is also a prerequisite for some digital signatures and message authentication codes (HMACs), where the signing algorithm requires a canonical byte representation of the payload.

Who Should Use This Formatter?

API developers testing and optimising API responses will find the minifier useful for measuring the exact byte size of a payload and for stripping whitespace before embedding JSON in build artifacts or Docker image configurations.

Front-end engineers embedding JSON in JavaScript bundles, HTML <script> tags, or static configuration files should always use minified JSON to avoid shipping unnecessary whitespace to the client.

DevOps and platform engineers managing Kubernetes manifests, Terraform state files, or other infrastructure JSON need minified output when checking values into Git or diffing configurations between environments. The key-sort option makes those diffs more readable. Pair this with the JSON Formatter to switch between human-readable and compact forms during debugging.

Data engineers building ETL pipelines that exchange large JSON payloads between services benefit from minification at each pipeline stage to keep inter-service traffic lean.

What Insights Does the JSON Minifier Give You?

Seeing the byte size of the minified output (visible in the character count of the output box) gives a concrete measure of the true data size stripped of formatting overhead. Comparing the minified and pretty-printed sizes shows exactly how much whitespace your JSON contains, a useful diagnostic when optimising API responses.

The key-sorting option also reveals structural inconsistencies: if the same logical object appears with keys in different orders across two API calls, the minified key-sorted forms will be different even if the data is identical, which is a signal that key ordering is not enforced at the producer.

How to use this JSON Min calculator

  1. Paste your JSON into the Raw JSON box, this can be pretty-printed or already partially minified.
  2. Optionally enable Sort keys alphabetically to produce canonical, order-independent output.
  3. The Minified JSON output appears instantly and updates on every keystroke.
  4. If the input is invalid JSON, the output will show a parse error message with the position of the problem.
  5. Click Copy to copy the minified result to your clipboard.

Formula & Methodology

Minification uses two built-in JavaScript functions:

js JSON.stringify(JSON.parse(input)) 

JSON.parse() converts the input string into a JavaScript value tree, validating it in the process. JSON.stringify() serialises it back to a string with no indentation argument, which produces the most compact representation.

When key sorting is enabled, a recursive pass sorts each object's keys alphabetically before stringification:

js function sortKeys(val) {   if (Array.isArray(val)) return val.map(sortKeys);   if (val !== null && typeof val === 'object') {     return Object.fromEntries(       Object.keys(val).sort().map(k => [k, sortKeys(val[k])])     );   }   return val; } JSON.stringify(sortKeys(JSON.parse(input))); 

Arrays are not reordered, only object keys are sorted. The sort is lexicographic (case-sensitive), which is the same order used by most diff and comparison tools.

Before:
json {   "name": "thecalcu.com",   "calculators": 134,   "tags": ["finance", "tax", "math"] } 

After (minified, keys sorted):
json {"calculators":134,"name":"thecalcu.com","tags":["finance","tax","math"]} 

Frequently Asked Questions

JSON minification removes all whitespace, spaces, tabs, and newlines, that is not part of a string value, producing the smallest possible valid JSON representation of the same data. A 10 KB pretty-printed JSON file can typically be reduced to 4–6 KB when minified. The structure, values, and key names are identical to the original; only the formatting whitespace is stripped.
Minified JSON is faster to transmit over a network because it is smaller. For APIs that return large JSON payloads, product catalogues, configuration files, search results, every kilobyte saved reduces bandwidth costs and latency, particularly for mobile users on slower connections. Minified JSON also reduces memory usage and parse time slightly, since the parser processes fewer bytes.
Beautification (also called pretty-printing) adds consistent indentation and newlines to make JSON human-readable. Minification removes all of that whitespace to make JSON machine-readable and as small as possible. Both operations produce valid JSON that contains exactly the same data. Use beautified JSON when reading or editing; use minified JSON when transmitting or storing in production.
When this option is enabled, the keys in every JSON object are sorted alphabetically before minifying. Sorting keys is useful for diff-based version control (predictable key order makes diffs easier to read), for deterministic output when comparing two JSON structures, and for caching scenarios where the same data encoded in different key orders would otherwise produce different byte sequences.
Yes. Key sorting is applied recursively, every nested object at every depth has its keys sorted. Arrays are not reordered; only the keys within each object are sorted. The sort is a standard lexicographic (alphabetical) sort on the key strings.
Paste your JSON into the Raw JSON box. The minified output appears instantly in the Minified JSON field below. Optionally enable 'Sort keys alphabetically' if you want deterministic key ordering. Click the Copy button to copy the result to your clipboard.
The minifier uses the browser's built-in `JSON.parse()` to validate the input before reformatting it. If the input is not valid JSON, the output will show a clear error message (e.g. 'Invalid JSON: Unexpected token at position 14') instead of attempting to fix or guess at the correct structure. Use the [JSON Formatter](/json-formatter/) to identify and locate parse errors more easily.
Nothing is transmitted. All minification happens entirely in your browser using the built-in `JSON.parse()` and `JSON.stringify()` functions. The JSON you paste is never sent to any server, stored, or logged. This makes it safe to use with API keys, configuration secrets, database schemas, or any other sensitive JSON content.
Yes, once the page has loaded, the tool runs without a network connection. The minification logic is pure JavaScript that runs locally in your browser tab.
The tool is limited only by your browser's available memory and JavaScript engine limits, not by any server-side restriction. In practice, files up to several megabytes process in under a second. Very large files (tens of megabytes) may cause the browser tab to pause briefly while parsing. For extremely large files, a command-line tool like `jq -c '.'` may be more appropriate.
Yes, minifying and sorting keys on two JSON objects produces a canonical, whitespace-free representation that you can compare with a text diff tool. Two JSON objects that contain identical data but have keys in different orders will produce byte-for-byte identical output when minified with key sorting enabled.
Also known as
JSON minifierminify JSONcompress JSONcompact JSONremove JSON whitespace