Skip to content
HandyKit

Minify JSON: What It Does and When to Use It

· 2 min read

Minifying JSON removes the whitespace between values. It takes formatted JSON, with its indentation and line breaks, and returns the same data on one line.

The JSON Minifier does this in your browser. This guide explains what changes, what stays the same, and when minifying helps.

What minifying does

Minifying removes the spaces, tabs and line breaks between values. That whitespace has no meaning in JSON, so minified JSON parses to exactly the same data. Only the text changes.

Formatted:

{
  "name": "Ada Lovelace",
  "languages": ["en", "fr"],
  "active": true
}

Minified:

{"name":"Ada Lovelace","languages":["en","fr"],"active":true}

The space inside "Ada Lovelace" stays: spaces inside strings are data.

What does not change

  • Strings keep their contents, including spaces.
  • Numbers keep their values, and integers too large for JavaScript are not rounded.
  • Keys keep their order, unless you ask for them to be sorted.

When to minify

Minify when one compact line is more useful than a readable layout:

  • Storing JSON in a database column or an environment variable.
  • Sending smaller payloads.
  • Putting JSON on one line, such as in a log entry or a test fixture.

When not to minify

Don't minify files people read and edit, such as config files in a repository. Diffs and code review are much easier with formatted JSON, because each value sits on its own line.

Minifying API responses also saves less than it seems. Servers usually compress responses with gzip or Brotli, which already removes most of the size cost of whitespace.

Sort keys for stable output

With Sort keys A to Z ticked, the same data always gives the same output, whatever the original key order. That makes minified JSON easier to compare, hash or cache. Arrays keep their order, because order matters in arrays.

Going back and comparing

Paste minified JSON into the JSON Formatter to indent it again. Formatting and minifying are exact opposites, so you can move between the two without losing anything.

To check whether two documents hold the same data, use JSON Compare. It ignores formatting and key order, so you don't need to minify or sort first.

Try it

Paste your JSON into the JSON Minifier and copy the result. It runs in the browser tab, so nothing is sent to a server, logged or stored.

Tools in this guide

  • JSON Minifier

    Remove whitespace from JSON to make it as small as possible, and see how much you save before and after gzip compression.

  • JSON Formatter

    Paste or open JSON to pretty-print it, explore it as a tree, or repair almost-JSON. Errors are pinpointed by line and column, with a suggested fix.

  • JSON Compare

    Paste two JSON documents to see exactly what changed: added, removed and changed values, each with its path. Key order and formatting are ignored.

  • · 2 min read

    How to Compare Two JSON Files

    Find what changed between two JSON documents, ignoring key order and formatting. A worked example, how to read JSONPath, and how arrays and numbers compare.

  • · 2 min read

    How to Convert JSON to CSV, YAML or XML

    Turn JSON into a CSV spreadsheet, YAML or XML, with worked examples showing how nested objects, arrays and null values are handled, and how to open it in Excel.

  • · 4 min read

    Common JSON Errors and How to Fix Them

    Trailing commas, single quotes, comments, True and None: the JSON syntax errors developers hit most often, what each error message means, and how to fix it.