# JSON Minify Online

> Minify JSON online: strip every insignificant space and line break, cut payload size by around 40 percent, and keep every value identical.

Source: https://devplain.com/json-minify-online/
Last updated: 2026-10-29

Minify JSON online: strip every insignificant space and line break, cut payload size by around 40 percent, and keep every value identical.

## How It Works

Minifying JSON means removing the whitespace that only exists for humans. This page parses the document with the browser's JSON engine and writes it back out with no indentation and no separators between tokens, so the result is the shortest text that carries the same value.

**What comes out.** Every space, tab and line break that sits between tokens disappears: the gaps around colons and commas, the newlines that separate properties, and the indentation in front of nested keys. In a typical pretty-printed object, that is most of the file. A small object of 39 characters shrinks to 17, a 56 percent reduction; a nested sample of 121 characters shrinks to 72, a 40 percent reduction. Files that are mostly values rather than punctuation gain less, because there is less to remove.

**What stays exactly the same.** Every key, every value and every structural character: braces, brackets, colons, commas and quotes. Whitespace inside a string is data, not formatting, so a value containing two spaces still contains two spaces. Key order is preserved as parsed, apart from integer-like keys, which the engine always sorts ahead of the others.

**Why it re-serialises instead of stripping characters.** A naive minifier deletes whitespace with a regular expression and cannot tell a space inside a string from a space between tokens, so it corrupts values. Parsing first means the engine has already decided what is structure and what is data, and the output is generated from the parsed value. The side effect is that the document must be valid JSON before it can be minified: comments, trailing commas and single quotes are rejected with a line number instead of being silently mangled.

**What else changes along the way.** Number literals come back in canonical form — 1.0 becomes 1 and 1e3 becomes 1000 — and a repeated key keeps only its last value. Both are consequences of parsing into a JavaScript value, and both are worth knowing before you minify a file you intend to compare byte for byte.

**When not to minify.** Keep the pretty version for anything a human edits or reviews: configuration files in a repository, API fixtures, and JSON you will read in a diff. Minify the copy you ship — a request body, a bundled data file, an embedded payload — and keep the readable original in source control.

Minification runs entirely in the tab, so an API response or a config file with credentials never leaves the browser.

## Examples

### Input

```
{
  "a": 1,
  "b": [
    1,
    2
  ]
}
```

### Output

```
{"a":1,"b":[1,2]}
```

The standard case: every newline and indent disappears, the structure does not. 39 characters become 17.

### Input

```
{ "a": 1, "b": [1, 2] }
```

### Output

```
{"a":1,"b":[1,2]}
```

Spaces on one line are removed too, so minifying an already single-line document still helps.

### Input

```
{"msg":"keep  these  spaces"}
```

### Output

```
{"msg":"keep  these  spaces"}
```

Boundary case: whitespace inside a string is data, so the document is returned unchanged — a regex-based stripper would corrupt it here.

### Input

```
{
  "a": 1,
}
```

### Output

```
Expected double-quoted property name in JSON at position 12 (line 3 column 1) (line 3)
```

Boundary case: a trailing comma cannot be parsed, so the page reports the line instead of producing broken output.

## Frequently Asked Questions

**What exactly does minifying JSON remove?**

Only whitespace that sits between tokens: the spaces around colons and commas, the line breaks between properties, and the indentation before nested keys. Braces, brackets, quotes, keys and values are untouched, and spaces inside a string value are data, so they survive. The output is the shortest text that represents the same document.

**How much smaller does the file get?**

For pretty-printed JSON, usually 30 to 60 percent. A 39-character object with two-space indentation becomes 17 characters, a 56 percent saving; a nested 121-character sample becomes 72, a 40 percent saving. The gain depends on structure: files dominated by long string values have less whitespace to remove, so they shrink less.

**Why does my JSON with comments fail to minify?**

Because comments are not part of JSON. The minifier parses the document first, and a parser rejects comments, trailing commas and single quotes rather than guessing what you meant. If you need comments, keep them in a JSONC or JSON5 source file and minify the generated JSON instead, which is how most build pipelines handle it.

**Is minified JSON safe to send to an API?**

Yes. Whitespace between tokens carries no meaning in JSON, so a minified body parses to exactly the same value. Watch two things instead: numbers are re-serialised in canonical form, so 1.0 becomes 1, and a repeated key keeps only its last value. Neither matters for a body you generate from a validated object.

**When should I not minify?**

When a human will read or diff the file. Keep pretty JSON for repository config, test fixtures and anything under code review, because a single-line file makes every change look like a full rewrite. Minify the copy you ship and keep the formatted original in source control.

## Limitations & Accuracy

The document must be valid JSON before it can be minified, so comments, trailing commas and single quotes return a syntax error with a line number instead of output. Numbers are re-serialised in canonical form, so 1.0 becomes 1 and 1e3 becomes 1000, and integers beyond 9007199254740991 lose precision because JSON.parse returns doubles. A repeated key keeps only its last value, and integer-like keys are emitted before string keys. Minified output is one line, which is the wrong shape for review or diffing.

## Related Tools

- [JSON Formatter](https://devplain.com/json-formatter/)
- [JSON Validator with Error Line Numbers](https://devplain.com/json-validator-with-error-line-numbers/)
- [All tools](https://devplain.com/tools/)

Last updated: 2026-10-29

