SimplyCalculated.org

JSON Formatter & Minifier

Paste any JSON to get a pretty-printed version and a minified version at the same time. If your input isn't valid JSON, you get a precise error instead of garbage output. Everything runs locally in your browser.

100% private: everything is processed in your browser's memory — nothing you enter is uploaded to a server, logged, or stored.

JSON Formatter & Minifier

What Is a JSON Formatter?

A JSON formatter (also called a pretty-printer or beautifier) takes a JSON document and rewrites it with consistent, human-readable indentation — newlines after each value, nested objects and arrays indented by two spaces, and one key-value pair per line. Its sibling, a JSON minifier, does the exact opposite: it strips every piece of insignificant whitespace to produce the smallest possible single line of JSON. Both are cosmetic transformations. Because whitespace carries no meaning in JSON, the formatted version and the minified version parse to precisely the same data — the only difference is who the output is optimized for: a human reading it, or a network transferring it.

Why Format JSON?

JSON arrives in the wild in every imaginable state: minified API responses, one-line configs, copy-pasted log snippets, or editor-formatted files with three-space tabs. When you need to read that data — to debug an API response, review a config change, or understand the shape of a webhook payload — a wall of text is nearly impossible to scan. Formatting makes the structure visible at a glance: how deeply an object is nested, which keys belong to which object, whether an array has one element or a thousand. It is also the fastest way to validate that a document you are about to hand to a colleague or commit to a repository is well-formed: if it doesn't format, it doesn't parse.

Why Minify JSON?

Minified JSON exists for machines. Every byte of whitespace you remove shrinks the payload, which matters when JSON travels over a network — a compact response is faster to transfer and cheaper to store, and some APIs even enforce a size limit. Minification is also useful before embedding JSON inside other text: in a code file, a shell command, a URL fragment, or a data URI, where every character of overhead counts. On typical documents, removing whitespace saves 20–40% of the file size — for large configs or datasets that adds up quickly. The tool produces the minified form of the parsed data, so the output is canonical regardless of how messy the input's whitespace was.

The Standard: RFC 8259

This tool implements strict JSON as defined in RFC 8259 (the current IETF standard, successor to RFC 7159 and the original RFC 4627). The specification is deliberately small: a JSON document is one value — an object, array, string, number, boolean, or null — and the grammar has a few non-negotiable rules. Strings must be wrapped in double quotes (single quotes are invalid), object keys must be quoted, numbers must follow the JSON number grammar (no leading zeros, no NaN or Infinity), there are no comments, and no trailing commas are allowed. The whitespace rules are the mirror image: spaces, tabs, and newlines may appear between tokens anywhere, in any amount, and are completely ignored by parsers — which is exactly why formatting and minifying are always safe, reversible-of-structure operations.

How the Tool Works

The pipeline is simple: the input is parsed into an in-memory value, then re-serialized. Parsing doubles as validation — if the input violates the grammar at any point, the parser throws with the exact position of the problem, and the tool shows that message instead of guessing. If parsing succeeds, the value is serialized twice: once with two-space indentation (formatted) and once with no whitespace at all (minified). Because serialization always produces canonical output, feeding this tool already-formatted or already-minified JSON is harmless — it simply rewrites the same data in the requested style.

What Happens to Your Input, Step by Step

Following a single document through the tool makes the behavior predictable. When you paste {"name":"Ada","age":36}, the parser first scans the text and builds an in-memory object — this is where the RFC 8259 grammar is enforced, so a trailing comma, an unquoted key, or a stray token stops the parse at the exact offending position. If the parse fails, you see the error and your previous valid output stays put; nothing is guessed. If it succeeds, the value is re-serialized twice: once with two-space indentation for reading, once with zero whitespace for transporting. Because both outputs come from the same parsed value, they can never disagree about the data — formatting and minifying are two views of one object, not two transformations.

On larger documents the same pipeline runs in a single pass in your browser's memory. A multi-megabyte config parses in well under a second, and since nothing is ever uploaded, even sizeable or sensitive documents are safe to process here — the only practical limit is the memory your browser gives the tab.

JSON vs YAML vs XML

JSON became the default data-exchange format because it is a strict subset of JavaScript syntax — any JavaScript developer can read it, every language has a parser, and the strictness that makes it annoying to hand-write is exactly what makes it reliable to round-trip. YAML is friendlier for hand-written config (comments, multi-line strings, no braces), but its indentation rules and type coercion produce subtle bugs and it is a poor interchange format. XML survives where documents need attributes, namespaces, and schema validation — office file formats, SOAP, and RSS — but for JSON-compatible data exchange it is far heavier than necessary. In short: JSON is the right default for data between systems, YAML for config you write by hand, and XML only where the ecosystem demands it.

Worked Example & Reference

Paste this minified document into the tool — the formatted output should match exactly:

{"users":[{"id":1,"active":true},{"id":2,"active":false}]}
Input (minified) Formatted output
{"name":"Ada","age":36}
{
  "name": "Ada",
  "age": 36
}
{"users":[{"id":1},{"id":2}]}
{
  "users": [
    {
      "id": 1
    },
    {
      "id": 2
    }
  ]
}
{"a":[1,2,null]}
{
  "a": [
    1,
    2,
    null
  ]
}
42 / "hi" / true / null 42 / "hi" / true / null
{"name":"Ada",} Invalid — trailing comma
{name:"Ada"} Invalid — unquoted key

Note that the top-level values 42, "hi", true, and null are all valid JSON documents by themselves — the standard does not require a top level object or array.

Troubleshooting & Common Mistakes

Trailing Commas

The most frequent error: a comma after the last item in an object or array ({"a":1,}). JavaScript and other languages allow trailing commas, JSON does not — remove the final comma and the document parses.

Single Quotes and Unquoted Keys

JSON strings must use double quotes: 'name' and name: are both invalid; "name": is required. If you pasted JavaScript object syntax or a config file written in a permissive dialect, this is almost certainly the issue.

Comments and Non-Standard Values

Comments (// or /* */) are not part of JSON, and neither are NaN, Infinity, or undefined. If your file needs comments, it is really JSONC or JSON5 — this tool follows strict RFC 8259.

Two Documents in One

Pasting two JSON values back to back ({"a":1} {"b":2}) fails — one document, one value. This is common when copying from logs that concatenate several JSON lines; split them first.

Frequently Asked Questions

Does formatting or minifying change my data?
No. Whitespace in JSON is insignificant to the parser, so both tools preserve the exact same data — same keys, same values, same order — and only change the whitespace around it. A formatted and a minified version of the same document parse to precisely the same object. The one thing to be aware of is duplicate keys: if your JSON contains the same key twice, standard parsing keeps the last value, and the re-serialized output will contain it only once.
Does the formatter preserve key order?
Yes. JavaScript objects preserve the insertion order of string keys (and the ECMAScript specification guarantees this), so the re-serialized output lists keys in the same order they appeared in your input. Numeric-like keys and symbol keys follow the language's standard ordering rules, but for ordinary JSON documents the order is unchanged.
Why is my JSON being rejected as invalid?
The most common causes are: trailing commas (e.g. {"a":1,} — JSON does not allow them), single quotes around strings or keys ('a' is invalid — JSON requires double quotes), unquoted keys ({name:"Ada"} is invalid), comments of any kind, and values like NaN or Infinity that the JSON grammar does not define. The error message shows the exact position where the parser stopped, which points right at the offending character.
Can JSON contain comments?
No — the JSON specification (RFC 8259) has no syntax for comments. If you need comments, you are looking at a JSON dialect instead: JSON5, JSONC ("JSON with Comments", used by some config files like tsconfig.json), or YAML. This tool implements strict standard JSON, so pasting a file with comments will show a parse error — strip the comments first, or use a tool built for that dialect.
What happens with duplicate keys?
Strictly speaking, JSON allows duplicate names in an object, and the RFC says behavior is unpredictable. In practice, every major parser — including the one in your browser — keeps the last occurrence and silently drops the earlier ones. This tool behaves the same way: the formatted output will contain the key once, with the last value you wrote. If that surprises you, it is a sign your source data has a bug worth fixing.
Is it safe to paste sensitive JSON here?
Yes. Everything runs entirely in your browser — parsing and re-serialization happen in memory with no server, network request, or storage involved. Nothing you paste is uploaded or logged. That said, if the JSON contains secrets like API keys, treat any paste as you would any clipboard content and be mindful of what you share.
What is the difference between formatting and minifying?
Formatting (pretty-printing) inserts newlines and two-space indentation so nested objects and arrays are easy to read — the same output you would get from a beautifier in an editor. Minifying removes all insignificant whitespace and produces one compact line that parses to the identical data. Formatting is for humans debugging or reviewing; minifying is for machines — smaller payloads over the network, and smaller files when JSON is embedded in code or config.