JSON Minify Online

Remove all whitespace and compress JSON to its smallest valid form — instantly.

1234567891011121314151617181920
1234567891011121314151617181920

JSON minification removes all non-essential whitespace — spaces, tabs, and newlines — from a JSON document, producing the most compact valid JSON string possible. The output is semantically identical: every parser reads minified and formatted JSON exactly the same way. Typical size reduction is 20–50% depending on original indentation.

shieldRuns entirely in your browser
cloud_offNo data stored or uploaded
boltAuto-minifies on paste
volunteer_activismFree forever

What Is JSON Minification?

JSON minification removes all non-essential whitespace from a JSON document — every space between keys and values, every newline between properties, every tab used for indentation — while leaving the actual data completely intact. The result is a single compact line containing exactly the same information as the original multi-line document.

This is possible because whitespace is not semantically meaningful in JSON. Per RFC 8259 (the JSON specification), insignificant whitespace can appear before or after any JSON token, and parsers are required to ignore it. The specification defines whitespace as space (U+0020), tab (U+0009), line feed (U+000A), and carriage return (U+000D).

The result of minification is 100% identical in meaning to the source. A minified JSON document will parse to exactly the same in-memory structure in every language — JavaScript, Python, Go, Java, C#, Ruby, or any other. The decision to minify is purely operational: smaller size for transmission and storage, not for computation.

Quick Facts

Typical size saving
20–50%
Data loss
None
Parse time change
~Same
RFC spec
RFC 8259
Idempotent?
Yes
Reversible?
Yes

How JSON Minification Works

A JSON minifier does not simply strip all spaces — it must parse the JSON first to understand which whitespace is structural and which is inside a string value.

looks_one

Parse

The minifier reads the JSON string and builds an in-memory representation — a tree of objects, arrays, strings, numbers, booleans, and nulls. This step validates the JSON is well-formed and identifies all structural characters vs. string content.

looks_two

Serialize

The minifier serializes the in-memory tree back to a string — but without any indentation or extra whitespace. Structural characters ({}, [], :, ,) are written with no surrounding spaces.

Why parse first? Whitespace inside string values must be preserved. For example, "description": "hello world" — the space between "hello" and "world" is inside the string and cannot be removed. A naive character-by-character strip would corrupt string values. Parsing first ensures only structural whitespace is removed.

Before & After — Real Size Savings

A realistic API response formatted with 2-space indentation alongside its minified equivalent.

Formatted (2-space indent)312 chars
{
  "endpoint": "/api/users/4821",
  "method": "GET",
  "user": {
    "id": 4821,
    "name": "Alice Chen",
    "email": "alice@example.com",
    "role": "admin",
    "active": true,
    "teams": [
      "platform",
      "security"
    ]
  },
  "meta": {
    "version": "v2.1",
    "count": 1
  }
}
Minified186 chars — 40% smaller
{"endpoint":"/api/users/4821","method":"GET","user":{"id":4821,"name":"Alice Chen","email":"alice@example.com","role":"admin","active":true,"teams":["platform","security"]},"meta":{"version":"v2.1","count":1}}

Saved 126 characters — and this is just one response. At 10,000 API requests per day, that is 1.26 MB of bandwidth saved daily from a single endpoint.

When Should You Minify JSON?

Minification pays off whenever JSON is transmitted, stored, or embedded — but adds no value while actively developing where readability matters.

api

REST API Responses

Minifying API responses reduces payload size by 20–50%, cutting bandwidth costs and improving response times — especially on mobile networks and metered connections.

settings

Environment Variables

Environment variables must be single-line strings. Minifying a JSON config makes it safe to set as an env var without shell quoting issues or line-break corruption.

storage

Database Storage

JSON columns in PostgreSQL, MySQL, or MongoDB benefit from smaller payloads — reducing storage footprint and index overhead on JSON fields.

web

Bundled Web Assets

JSON files bundled into frontend apps contribute to bundle size. Minifying them reduces download size and parse time at page load — especially for large i18n or config files.

data_object

HTML Data Attributes

JSON embedded in data-* attributes must be compact. Minified JSON avoids line-break issues when injected into HTML templates or server-rendered pages.

compare_arrows

Canonical Form for Hashing

When signing or comparing JSON payloads (JWTs, webhooks, idempotency keys), minification produces a canonical form — eliminating whitespace-only differences.

API Performance Impact

The performance argument for minifying JSON is most compelling at scale. Consider a single endpoint returning a 5 KB formatted JSON response:

ScenarioPayload SizeDaily RequestsDaily Bandwidth
Formatted JSON (4-space indent)5.0 KB100,000500 MB
Minified JSON (~35% saving)3.25 KB100,000325 MB
Minified + gzip~0.8 KB100,000~80 MB

At 100,000 requests per day, minification alone saves 175 MB of daily bandwidth from a single endpoint. Adding HTTP response compression reduces it to ~80 MB — an 84% total reduction from the baseline. On cloud platforms where egress is billed per GB, these savings translate directly to lower infrastructure costs.

JSON Minify vs gzip — Do They Stack?

If the server gzips responses anyway, why minify? The answer is that they compress different things and work better together than either alone.

compressJSON Minification

  • Removes redundant whitespace characters
  • Reduces input size before any other compression step
  • Works at the JSON content level
  • Zero CPU overhead at request time

archivegzip / Brotli

  • Compresses repeated byte patterns in any data
  • Applied at the HTTP transport layer
  • Requires Accept-Encoding header support
  • CPU overhead at request/response time

Best practice: Minify JSON at build time or before storing it. Let the HTTP layer handle gzip automatically. Smaller minified input means gzip has less to process — and repeated key names across a JSON array compress even more efficiently when whitespace noise is removed. Together they typically produce 70–85% total size reduction compared to formatted JSON transmitted uncompressed.

How to Minify JSON in Code

Every language with a JSON library can minify in one step: parse to an in-memory object, then serialize back without indentation.

JavaScript / Node.jsexpand_more
// JSON.stringify without third argument = no whitespace (minified)
const minified = JSON.stringify(JSON.parse(jsonString));

// From a file (Node.js)
const fs = require('fs');
const data = fs.readFileSync('data.json', 'utf8');
const minified = JSON.stringify(JSON.parse(data));
fs.writeFileSync('data.min.json', minified);

// Express: disable pretty-printing in production
app.set('json spaces', 0); // default — already minified
res.json(data);
Pythonexpand_more
import json

json_string = '{ "name": "Alice", "age": 30 }'
# separators=(",", ":") removes the default space after , and :
minified = json.dumps(json.loads(json_string), separators=(',', ':'))
# Output: {"name":"Alice","age":30}

# From a file
with open('data.json') as f:
    data = json.load(f)
with open('data.min.json', 'w') as f:
    json.dump(data, f, separators=(',', ':'))
Goexpand_more
package main

import (
    "bytes"
    "encoding/json"
    "fmt"
)

func main() {
    src := []byte(`{ "name": "Alice", "age": 30 }`)

    // json.Compact removes all insignificant whitespace
    var buf bytes.Buffer
    if err := json.Compact(&buf, src); err != nil {
        panic(err)
    }
    fmt.Println(buf.String())
    // Output: {"name":"Alice","age":30}
}
Java (Jackson)expand_more
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.JsonNode;

ObjectMapper mapper = new ObjectMapper();
// writeValueAsString defaults to compact — no INDENT_OUTPUT
JsonNode node = mapper.readTree(jsonString);
String minified = mapper.writeValueAsString(node);
PHPexpand_more
<?php
$jsonString = '{ "name": "Alice", "age": 30 }';

// json_encode without JSON_PRETTY_PRINT = compact output
$minified = json_encode(json_decode($jsonString));
// Output: {"name":"Alice","age":30}

// From a file
$data = json_decode(file_get_contents('data.json'));
file_put_contents('data.min.json', json_encode($data));
C# (System.Text.Json)expand_more
using System.Text.Json;

string jsonString = """{ "name": "Alice", "age": 30 }""";

// Default options: WriteIndented = false → compact output
using var doc = JsonDocument.Parse(jsonString);
string minified = JsonSerializer.Serialize(doc.RootElement);
// Output: {"name":"Alice","age":30}

// Newtonsoft.Json
using Newtonsoft.Json;
var obj = JsonConvert.DeserializeObject(jsonString);
string minifiedNJ = JsonConvert.SerializeObject(obj, Formatting.None);

JSON in Environment Variables

Environment variables must be single-line strings. Multi-line formatted JSON breaks in most shells and CI/CD platforms. Minification is the fix.

cancelBroken — multi-line
# .env — shell errors on newlines inside value
DATABASE_CONFIG={
  "host": "db.example.com",
  "port": 5432,
  "name": "myapp"
}
check_circleWorks — minified
# .env — single line, no shell issues
DATABASE_CONFIG={"host":"db.example.com","port":5432,"name":"myapp"}

# Reading in Node.js
const config = JSON.parse(process.env.DATABASE_CONFIG);
console.log(config.host); // "db.example.com"

This pattern is standard in cloud deployments on AWS Lambda, Vercel, Railway, Fly.io, and GitHub Actions — anywhere a complex JSON config must be passed as a single environment variable. Paste your formatted config into this tool, click Minify, then paste the result into your env var field.

JSON Minify vs Pretty Print vs One Line

These tools all deal with whitespace in JSON — here is exactly how they differ.

FeatureJSON MinifyJSON Pretty PrintJSON to One Line
Primary purposeRemove whitespace + show savingsAdd indentation for readabilityCollapse to single line
Output formatMost compactMulti-line, indentedSingle line, no whitespace
Size reduction✓ Maximum✗ Increases size✓ Same as minify
Shows savings✓ Bytes + %✗ No✗ No
Human readable✗ No✓ Yes✗ No
Validates JSON✓ Yes✓ Yes✓ Yes
Best forAPIs, storage, env varsDebugging, code reviewShell scripts, quick collapse
verified

JSON Has Errors? Validate First

The minifier requires valid JSON. If minification fails, use the JSON Validator to pinpoint the exact syntax error, or the JSON Parser to inspect the structure.

Validate JSON

Frequently Asked Questions

What is JSON minification?

expand_more

JSON minification removes all non-essential whitespace — spaces, tabs, and newlines — from a JSON document, producing the smallest possible valid JSON string. The result is semantically identical to the original: every parser reads minified and formatted JSON exactly the same way. Typical size reduction is 20–50% depending on original indentation.

Does minifying JSON change its meaning?

expand_more

No. Whitespace is not significant in JSON per RFC 8259. Parsers treat minified and formatted JSON identically — only file size and human readability differ.

How much does minification reduce JSON size?

expand_more

Savings depend on original indentation. A 4-space indented file with deep nesting can see 30–50% size reduction. A 2-space file with shallow structure might see 15–25%. This tool shows the exact byte and percentage savings so you can measure the impact.

Does minification replace gzip?

expand_more

No — they stack. Minify first to remove redundant whitespace, then gzip compresses repeated character patterns at the HTTP transport layer. Together they typically achieve 70–85% total size reduction compared to formatted uncompressed JSON.

Can I minify JSON that is already on one line?

expand_more

Yes. If the JSON already has no whitespace, minification returns it unchanged. It is idempotent — running it multiple times always produces the same output.

What is the difference between JSON minify and JSON to one line?

expand_more

They produce identical output — compact JSON on a single line with all whitespace removed. JSON Minify additionally shows the byte and percentage savings, making the compression impact visible.

Is minified JSON harder to debug?

expand_more

Yes — that is the trade-off. Minify for production and transmission, keep formatted JSON in development. Use the JSON Pretty Print tool to expand minified JSON back to a readable form whenever you need to inspect or debug it.

How do I minify JSON in JavaScript?

expand_more

Use JSON.parse then JSON.stringify without a third argument: const minified = JSON.stringify(JSON.parse(jsonString)). JSON.stringify defaults to no whitespace, producing the most compact valid form.

How do I minify JSON in Python?

expand_more

Use json.dumps with separators=(",", ":"): import json; minified = json.dumps(json.loads(json_string), separators=(",", ":")).

Is this JSON minifier free?

expand_more

Completely free with no account or signup required. All minification runs locally in your browser — your JSON is never sent to any server.

verified_user

About This Tool

Built by OpenFormatter · Last updated

compressLossless whitespace removal
lock100% browser-based — zero uploads
boltAuto-minifies on paste
starFree forever, no account needed
JSON Minify Online — Compress & Reduce JSON Size Free