FormatterHQ

JSON Minify

Remove every optional space and line break from JSON and see exactly how many bytes you saved. Your data is validated on the way, so the output is always parseable.

Input JSON
Output JSON
Ready.

How to use the JSON Minify

  1. Paste formatted JSON into the input editor, or load it with Upload file, Load URL or drag and drop.
  2. Click Minify. The output shows the document on a single line and the status bar shows the size before and after, for example 690 B → 448 B (35% smaller).
  3. Use Copy or Download to take the compact JSON.
  4. Need to read it again later? Click Format to expand it with a 2-space indent.

JSON minify: the same data in fewer bytes

To JSON minify a document means to delete the whitespace that only exists for human readers: indentation, line breaks and the spaces after colons and commas. Parsers ignore that whitespace, so the minified text describes exactly the same data while taking less room on disk and on the wire.

Whitespace inside string values is part of the data and is never touched. A value like "keep these spaces" comes out with all three spaces between each word.

Before and after

{
  "name": "Ada Lovelace",
  "note": "keep   these   spaces",
  "tags": [ "math", "poetry" ],
  "born": 1815
}

After Minify:

{"name":"Ada Lovelace","note":"keep   these   spaces","tags":["math","poetry"],"born":1815}

The status bar reports 111 B → 91 B (18% smaller). Sizes are measured in UTF-8 bytes, so accented letters and emoji count as the two to four bytes they really occupy, and anything above 1,024 bytes is shown in KB.

How much can you save?

It depends on how deeply the data is nested and how it was indented. The tool's own sample, a small company record indented with two spaces, drops from 690 to 448 bytes, a 35% saving. Documents indented with four spaces or tabs and many short values save more; documents made mostly of long text strings save less, because most of their bytes are inside strings.

Minify and gzip are different things

Most web servers compress responses with gzip or Brotli, and those algorithms are very good at squeezing repeated spaces. Measured with gzip at its default level, the same sample shrinks to 351 bytes when formatted and 309 bytes when minified. So on compressed HTTP traffic the gain from minifying is real but modest.

Minifying pays off more where no compression happens:

  • JSON stored in database columns, key-value stores or localStorage, where every byte counts against a quota.
  • Values placed in environment variables, HTTP headers, query strings or command-line arguments, which must fit on one line.
  • Fixtures and payloads embedded in HTML, JavaScript bundles or message queues.
  • Log lines, where one record per line keeps tools like grep useful.

If you need actual compression, the Gzip compress tool produces gzip output as Base64 or hex.

Things minifying also does

The input is parsed before it is written back out, which has a few side effects worth knowing. Invalid JSON is rejected with a line and column instead of being half-compressed. Numbers are rewritten in their shortest form, so 1.0 becomes 1 and 2.5E-3 becomes 0.0025. If a key appears twice in one object, only the last value remains. Key order and array order are otherwise preserved exactly.

Minify vs one line

Minified output has no spaces at all. When you want a single line that is still easy to scan, for example in a log message or a code review comment, the JSON to one line tool can keep one space after each colon and comma. To place minified JSON inside a string in code or another JSON document, escape it with JSON stringify.

Privacy

Minification runs locally in your browser; the JSON you paste is not transmitted. The server is involved only if you use Load URL (the file is fetched through it) or Save & Share (the input is stored so the link works).

JSON minify in Python

Parse the text with json.loads() and write it back with json.dumps(). The catch is that json.dumps() on its own does not minify: by default it puts a space after every comma and colon, so you have to pass separators=(",", ":"). It also escapes each non-ASCII character as \uXXXX, which makes the output longer; add ensure_ascii=False to keep characters such as ë as written, and save the result as UTF-8.

import json

pretty = """{
  "name": "Zoë",
  "tags": ["a", "b"],
  "active": true,
  "manager": null
}"""

data = json.loads(pretty)
print(json.dumps(data))
# {"name": "Zoë", "tags": ["a", "b"], "active": true, "manager": null}

minified = json.dumps(data, separators=(",", ":"), ensure_ascii=False)
print(minified)
# {"name":"Zoë","tags":["a","b"],"active":true,"manager":null}

print(len(pretty.encode("utf-8")), "->", len(minified.encode("utf-8")), "bytes")

The second line of output is exactly what the Minify button above returns for the same document, so this page works as a quick check on a script.

Frequently asked questions

Is minified JSON still valid JSON?
Yes. Whitespace between tokens is optional in the JSON grammar, so removing it produces a document that every parser reads the same way. The tool also validates the input first, so it never outputs broken JSON.
Does JSON minify change my data?
The values stay the same, but the text form of some numbers can change: 1.0 is written as 1 and exponents are expanded or shortened. If a key is repeated within an object, only its last value remains. Strings, key order and array order are kept.
Can I minify JSON with comments?
Comments are not valid JSON, so Minify reports them as an error. Use the Repair button on a formatter page or the JSON fixer to strip comments first, then minify the result.
How do I minify JSON on the command line?
With jq installed, jq -c . file.json prints compact output. In Node.js, JSON.stringify(JSON.parse(text)) does the same, and in Python you can use json.dumps(data, separators=(",", ":")).
How do I undo minification?
Click Format on this page to expand the JSON again with a 2-space indent. The original indentation style is not stored, but any formatter can re-indent the data because no information was lost.

Last updated October 3, 2026

Related tools

CSS Minifier Minify CSS online: remove whitespace and comments and merge rules to reduce stylesheet size. HTML Minifier Minify HTML online including inline CSS and JavaScript. JavaScript Minifier Minify JavaScript online with Terser to shrink file size for faster websites. XML Minify Minify XML by removing indentation, line breaks and comments. Shrink SOAP payloads, sitemaps and configs while keeping them valid. JSON Multiline String Converter Convert multi-line text into a valid JSON string with \n escapes, a JSON array of lines, or concatenated string literals. JSON Navigator Navigate JSON by path. Browse or filter the tree and click any key to see and copy the full path to that value. JSON Parser Parse JSON online: errors with line and column, the parsed values with their types, and the pitfalls of big integers and duplicate keys. JSON Patch Tester (RFC 6902) Apply RFC 6902 JSON Patch operations (add, remove, replace, move, copy, test) to a document and see exactly which step fails. JSON Patch Generator (Diff to Patch) Compare two JSON documents and generate the RFC 6902 JSON Patch that transforms the first into the second, with optional test ops. JSON Path Finder Click any value in a JSON tree to get its path as JSONPath, JavaScript, Python, PHP, jq or JSON Pointer — or list every path. JSON Pretty Print Pretty print JSON online with a 4-space default, 2 or 3 spaces or tabs, and see the matching JavaScript, Python, PHP and jq commands. JSON Reader Open a .json file in your browser and read it as a collapsible tree, a sortable table or a graph, with a filter to find any value.