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.

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.

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
What is JSON minification?
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.
Why minify JSON?
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.
What is the difference between minification and beautification?
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.
What does 'Sort keys alphabetically' do?
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.
Does key sorting affect nested objects?
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.
How do I minify JSON?
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.
Can the minifier fix invalid JSON?
No. 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.
Is my JSON uploaded anywhere?
No. 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.
Does this work offline?
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.
What is the maximum size of JSON I can minify?
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.
Can I use this to compare two JSON objects?
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.