JSON Formatter & Validator→Specialized Version
{ }

JSON Minifier

Minify and compress JSON

JSON Minifier

Compress JSON by removing all unnecessary whitespace with our free JSON minifier tool. Reduce file sizes for faster network transmission, smaller storage, and optimized API responses.

What JSON Minification Does

AspectBeforeAfter
WhitespacePresentRemoved
Line breaksMultipleNone
IndentationFormattedNone
File sizeLargerSmaller

Size Reduction Examples

OriginalMinifiedSavings
1 KB600 bytes40%
10 KB6 KB40%
100 KB60 KB40%
Typical savings: 30-50% depending on nesting depth and formatting.

Minification Code

``javascript function minifyJSON(jsonString) { try { const parsed = JSON.parse(jsonString); return JSON.stringify(parsed); } catch (e) { throw new Error('Invalid JSON: ' + e.message); } }

// Example const formatted = { "name": "John", "age": 30 }; console.log(minifyJSON(formatted)); // Output: {"name":"John","age":30} `

When to Minify JSON

Use CaseReason
API responsesFaster transmission
Configuration filesSmaller bundles
StorageReduced space
CachingMore data fits
Network transferLower bandwidth

Compression Comparison

FormatSizeReadable
Beautified JSON100%Yes
Minified JSON~60%No
Gzipped minified~15%No

Best Practices

1. Minify for production - Reduce payload sizes 2. Keep source beautified - Maintain readability in version control 3. Combine with Gzip - Server compression adds more savings 4. Validate first - Ensure JSON is valid before minifying

Use this minifier to optimize your JSON for production deployments.

Numbers Are the Recurring Problem

A JSON number is an IEEE 754 double. Three consequences that bite in production:

ValueWhat happens
Integers above 2⁵³Silently lose precision — send IDs as strings
Money as a float0.1 + 0.2 = 0.30000000000000004
Leading zeros007 is invalid JSON; "007" is a string
NaN and InfinityNot valid JSON at all
Twitter hit the first one publicly: 64-bit tweet IDs arrived in JavaScript rounded, so the API began sending an id_str alongside every id.

Keys, Order and Duplicates

Objects are formally unordered, though every JavaScript engine preserves insertion order for string keys — with one exception: integer-like keys sort numerically and come first.

`javascript JSON.stringify({ b: 1, 2: 2, a: 3 }); // {"2":2,"b":1,"a":3} `

Duplicate keys are not an error in the spec, and JSON.parse keeps the last one. Two parsers can legitimately disagree about which value wins, which has been the basis of real request-smuggling attacks.

Before and After

`json {"id":1,"name":"Ada","tags":["a","b"]} `

becomes

`json { "id": 1, "name": "Ada", "tags": ["a", "b"] } `

Formatting changes only whitespace. The parsed value is identical, which is why a formatter can never fix invalid JSON — it has to parse it first.

Rules That Prevent Most JSON Bugs

RuleWhy
No trailing commas{"a": 1,} is invalid JSON, though JavaScript accepts it in object literals
Double quotes only{'a': 1} is not JSON
Keys must be quoted{a: 1} is a JavaScript object, not JSON
No commentsThere is no comment syntax; JSON5 and JSONC are different formats
No undefined, NaN, InfinityJSON.stringify silently drops or nulls them
Numbers are IEEE 754 doublesIntegers above 2⁵³ lose precision — send them as strings

Parsing Safely

`javascript try { const data = JSON.parse(text); } catch (error) { // The message names the character offset, which is the fastest way // to find an unescaped quote in a large document. console.error(error.message); } `

JSON.parse` throws on invalid input rather than returning null, so it always belongs in a try/catch when the source is a file, a request body or a clipboard paste.

Frequently Asked Questions

What is JSON minification?

JSON minification removes all unnecessary whitespace (spaces, tabs, newlines) from JSON data, creating a compact single-line output that reduces file size while maintaining valid syntax.

How much space does minifying JSON save?

Typical savings are 30-50% depending on the original formatting. Deeply nested JSON with many indentation levels saves more. Combined with Gzip compression, total savings can exceed 85%.

Should I store JSON minified or formatted?

Store source files formatted for readability and version control. Minify for production deployment, API responses, and network transmission where size matters.

Related Tools

Explore other tools you might find useful:

More JSON Formatter & Validator tools

You might also need