DevToolsmith

JSON Minify

Paste JSON to compress it into a single line with all unnecessary whitespace removed. The tool validates the input first and shows exactly how many bytes you save.

Runs 100% in your browser — nothing is uploaded

JSON input
Tip: drop a file here142 chars · 142 bytes · 1 line
✓ Valid JSON8 keysdepth 2142 B → 142 B

⚠ 1 number can’t be stored exactly in JavaScript ($.id: 1234567890123456789). Kept exactly here, but JSON.parse would change it.

Minified JSON
142 chars · 142 bytes · 1 line

Example

Formatted, 112 bytes
{
  "user": {
    "id": 42,
    "name": "Ada Lovelace",
    "roles": ["admin", "editor"]
  },
  "active": true
}
Minified, 81 bytes
{"user":{"id":42,"name":"Ada Lovelace","roles":["admin","editor"]},"active":true}

That is 28% smaller, from whitespace alone. Strings, numbers and key order are untouched: 1.10 and 19-digit IDs survive, unlike with JSON.stringify(JSON.parse(text)). See which values JSON.parse changes.

When to minify JSON

  • Environment variables and CLI arguments that need JSON on a single line.
  • JSON Lines / NDJSON files, where each record must be one line.
  • Embedding JSON in a script tag, a data attribute or another string.
  • Storage in databases, caches or logs where size adds up.

For HTTP responses, enabling gzip or Brotli compression saves far more than minifying, and most frameworks already send compact JSON by default. Minify when the JSON is stored or transferred uncompressed.

Minify JSON on the command line and in code

# jq: -c means compact output
jq -c . data.json > data.min.json

# Python
python3 -c 'import json,sys; print(json.dumps(json.load(sys.stdin), separators=(",", ":")))' < data.json
JavaScript
JSON.stringify(JSON.parse(text)); // no indent argument = compact

Python’s json.dumps adds a space after , and : by default; pass separators=(",", ":") for truly compact output. Need it readable again? Use the JSON formatter.

Frequently asked questions

What does minifying JSON do?

It removes every space, tab and line break that is outside a string. The data is unchanged; only formatting is removed, so the file is smaller and fits on one line. Spaces inside string values are kept.

How much smaller does minified JSON get?

Typically 10–30% for API responses indented with 2 spaces, and more for deeply nested data or 4-space and tab indentation. The tool shows the exact saving. If the file is served with gzip or Brotli, the difference after compression is much smaller, often just a few percent.

Can minified JSON be turned back into readable JSON?

Yes, completely. Minification only removes whitespace, so the JSON formatter restores the indentation. Comments are not part of JSON, so there is nothing else to lose.

Is “JSON to one line” the same as minifying?

Yes. Minified JSON is a single line. If you need that line as a string inside another JSON document or source file, escape it afterwards with the JSON Escape tool so its quotes are backslash-escaped.