Skip to main content
ToolstikToolstik
BlogDeveloper

JSON Pretty Print vs Minify — What's the Difference?

ToolstikUpdated 6 min read
Side-by-side comparison of indented pretty-printed JSON and single-line minified JSON

Pretty printing adds line breaks and indentation so people can read nested JSON. Minifying removes every optional space and newline so the payload is as small as possible for machines. The data is identical either way. You can switch between the two in the JSON Formatter & Validator with the Format and Minify buttons, and both run entirely in your browser.

Try it now

JSON Formatter & Validator

Open full tool

Loading tool…

Side-by-side comparison

Pretty printMinify
What it doesAdds newlines and indentationRemoves all whitespace between tokens
Who it's forHumans: debugging, reviews, docsMachines: APIs, storage, embedding
Size (sample below)307 bytes at 2 spaces, 387 at 4194 bytes
Size after gzip (sample)191 bytes at 2 spaces162 bytes
Git diffsClean, line-by-lineOne giant changed line
Typical useConfig files, fixtures, logs you readHTTP bodies, env vars, query params, localStorage
Toolstik buttonFormat (2, 4, or 8 spaces)Minify

The size numbers come from the sample object in the next section, measured with Node.js. Your savings depend on how deeply nested your data is and how much of it is long string values, so measure your own payloads before making decisions based on size.

The same data, two ways

Pretty printed with 2 spaces:

{
  "user": {
    "id": 42,
    "name": "Ada Lovelace",
    "email": "ada@example.com",
    "roles": [
      "admin",
      "editor"
    ]
  },
  "settings": {
    "theme": "dark",
    "notifications": {
      "email": true,
      "push": false
    }
  },
  "tags": [
    "json",
    "api",
    "demo"
  ]
}

Minified:

{"user":{"id":42,"name":"Ada Lovelace","email":"ada@example.com","roles":["admin","editor"]},"settings":{"theme":"dark","notifications":{"email":true,"push":false}},"tags":["json","api","demo"]}

Notice that "Ada Lovelace" keeps its space. Minifiers only touch whitespace between tokens, never inside strings.

How much does minifying save?

For this sample, minifying cut 307 bytes down to 194, about 37% smaller than the 2-space version. With 4-space indentation the pretty version was 387 bytes, so the gap was bigger.

Compression changes the picture. Most servers and CDNs send JSON with gzip or Brotli, which squash repeated whitespace very well. Gzipped, the same sample was 191 bytes pretty versus 162 minified, a much smaller difference. Minifying still helps, just less than the raw numbers suggest:

  • Responses served over compressed HTTP: minifying gives a modest gain. It's worth doing because it's free, but don't expect big wins.
  • Places with no compression: URL query parameters, cookies, localStorage, environment variables, and message queues with size limits. Here minifying gives the full raw saving, and sometimes it decides whether the payload fits at all.
  • Logs: one JSON object per line (minified) is the standard for structured logging, because log tools split records on newlines.

When to pretty print

  • Debugging an API response. Paste it into the JSON Formatter, click Format, and the nesting becomes obvious.
  • Committed files. package.json, tsconfig.json, test fixtures, and translation files belong in version control pretty-printed, so diffs show exactly which value changed.
  • Documentation and bug reports. Readers shouldn't have to scroll sideways.
  • Code review of generated data. It's much easier to spot a wrong value when each one is on its own line.

When to minify

  • HTTP request and response bodies in production.
  • Embedding JSON in HTML <script> tags, environment variables, or CLI arguments, where newlines cause trouble.
  • Storage with size limits, such as cookies (commonly around 4 KB per cookie) or browser storage quotas.
  • Before Base64 encoding. Fewer bytes in means a shorter encoded string out. JWT payloads are minified JSON encoded this way. Paste one into the JWT Decoder to see it expanded, or experiment with the Base64 Encoder / Decoder.

How to do both in Toolstik

  1. Paste your JSON into the JSON input box of the JSON Formatter.
  2. To pretty print, choose 2 spaces, 4 spaces, or 8 spaces from the indent menu, then click Format.
  3. To minify, click Minify.
  4. Click Copy or Download (saves formatted.json).

Both buttons parse the JSON first. If it's invalid, you get an Invalid JSON message instead of output, so you'll never minify a broken file by accident. If that happens, common JSON errors and how to fix them covers the usual causes.

In code

const pretty = JSON.stringify(data, null, 2);
const minified = JSON.stringify(data);
import json
pretty = json.dumps(data, indent=2)
minified = json.dumps(data, separators=(",", ":"))

Python's default json.dumps puts a space after : and ,. Pass separators=(",", ":") for truly compact output. On the command line, jq . pretty prints and jq -c . minifies.

Pitfalls when switching formats

  • Comments disappear or break parsing. Standard JSON has no comments. Files like tsconfig.json are actually JSONC, which some tools accept. Running them through a strict parser, including Format or Minify, fails on the first //. Strip comments first, or keep those files in their own editor.
  • Duplicate keys collapse. {"a": 1, "a": 2} parses as {"a": 2} in JavaScript. Reformatting silently keeps only the last value, so a "harmless" round trip can change what a human reading the original file thought it said.
  • Large integers lose precision. JavaScript stores numbers as 64-bit floats, so integers above 9,007,199,254,740,991 can change when parsed and re-serialized. 12345678901234567890 comes back as 12345678901234567000. Keep big IDs as strings if you format them with browser tools.
  • Key order is preserved, not sorted. Neither button reorders keys, so two files with the same data in a different order will still produce different diffs. Sort keys in code (for example jq -S .) if you need stable output.
  • Trailing newline. Many editors and linters expect a newline at the end of a file. Generated output may not include one, so add it before committing.

The bottom line

Format for people, minify for machines, and let your build or server do the minifying so the files you edit stay readable. For a full walkthrough of the tool, read how to format and validate JSON online. To see the other browser-based utilities, start at free developer tools online.

Frequently asked questions