All tools

JSON minifier

Remove unnecessary whitespace from JSON.

JSON minifier
InputValid JSONJSON

Press Command or Control plus Enter to run. Tab inserts indentation; press Escape, then Tab, to leave the editor.

Result
Your result will appear here.
Ready6 lines · 116 chars

About the JSON minifier

A JSON minifier removes all the spaces, tabs and line breaks that make JSON readable but add nothing to the data. The result is a single compact line that is smaller to send over the network, store in a database or paste into an environment variable.

Minifying never changes your data: every key, value and array item stays exactly the same. Only the formatting whitespace between them is removed.

How to use the JSON minifier

  1. Paste formatted JSON into the Input editor, or click Load sample.
  2. Check the label above the editor to make sure the JSON is valid.
  3. Click Minify JSON or press Ctrl + Enter (Cmd + Enter on Mac).
  4. Click Copy result to copy the compact JSON.

Example

Compact a config before putting it in an environment variable

Input

{
  "featureFlags": {
    "newCheckout": true,
    "darkMode": false
  },
  "region": "eu-west-1"
}

Output

{"featureFlags":{"newCheckout":true,"darkMode":false},"region":"eu-west-1"}

Spaces inside strings are kept; only formatting whitespace is removed.

Common errors and how to fix them

Expected double-quoted property name in JSON at position 26 (line 1 column 27)

A trailing comma is left over after removing an item. Delete the comma after the last value.

Minified JSON breaks when pasted into a shell

The JSON contains double quotes, which the shell reads itself. Wrap the whole value in single quotes, export CONFIG='{"a":1}', or store it in a file.

Large numbers change after minifying

Integers above 9007199254740991 (2^53 - 1) cannot be stored exactly as JavaScript numbers, so any JavaScript tool rounds them. Send IDs like these as strings.

Good to know

  • Whitespace inside string values is part of the data, so it is kept exactly as it is.
  • The input must be valid JSON; fix any reported error first.
  • To turn minified JSON back into a readable layout, use the JSON formatter.

Frequently asked questions

How much smaller does minified JSON get?

It depends on how much indentation the original had. Deeply nested, pretty-printed JSON often shrinks by 20 to 40 percent; JSON that is already compact barely changes.

Is minified JSON slower to parse?

No. Parsers ignore formatting whitespace, so minified JSON parses at least as fast as formatted JSON and is quicker to download.

Should I minify JSON config files in my repository?

Usually not. Config files are read and edited by people, so readable formatting is more useful there. Minify JSON you send over the network or embed in other files.

How do I minify JSON in code or on the command line?

In JavaScript, JSON.stringify(JSON.parse(text)) returns compact JSON. In Python, use json.dumps(data, separators=(",", ":")), because the default separators keep a space after commas and colons. On the command line, jq -c . input.json > output.json does the same.