DevKit

JSON Formatter

Paste messy JSON, get clean indentation and an exact line number for every syntax error.

Free No sign-up Runs in your browser
Input
Output
0Bytes
0Lines
0Keys
0Max depth

Why format JSON at all

JSON has no significant whitespace, so a minified payload and a pretty-printed one are byte-different but semantically identical. Humans are the ones who need structure: indentation makes nesting visible, puts every key on its own line, and turns a 4,000-character wall into something you can actually review in a pull request.

Formatting is also the fastest way to catch a syntax error. If the parser fails, the JSON is invalid — and the error position tells you exactly where the structure broke, usually a comma, a quote or a bracket.

The five mistakes that break almost every JSON file

  • Trailing commas. {"a":1,} is fine in JavaScript objects and a syntax error in JSON.
  • Single quotes. JSON strings must use double quotes. 'a' is invalid.
  • Comments. // and /* */ are not part of the spec. Use JSONC only in files whose consumer explicitly supports it, such as tsconfig.json or VS Code settings.
  • Unquoted keys. {a:1} is JavaScript, not JSON.
  • Raw newlines inside strings. A literal line break must be written \n.

Pretty-print for review, minify for transport

Use 2-space indentation for configuration and test fixtures — it is the de facto standard and keeps diffs small. Minify before sending data over the wire: indentation can easily add 15–25% to a payload, and gzip cannot fully recover the loss because repeated space runs compress well but still cost entropy. A good build pipeline keeps JSON readable in the repository and minified on the CDN.

Sorting keys, and why it matters

Two files with the same content but different key order produce a large, noisy diff. Sorting keys recursively — which the Sort keys button does — makes JSON deterministic: the same data always serialises to the same bytes, which is invaluable for snapshot tests, content hashes and cache keys.

Numbers and precision

JSON numbers are IEEE-754 doubles. That means integers beyond 253 lose precision, and a 64-bit id like 9007199254740993 silently becomes 9007199254740992. If you work with database ids or financial values, keep them as strings in JSON and convert on the server.

Frequently asked questions

Is my JSON sent to a server?
No. Parsing and formatting happen in your browser via JSON.parse and JSON.stringify. Nothing is uploaded, so this is safe for internal configs and customer data.
Can it fix invalid JSON automatically?
Not automatically — silently guessing at malformed input is how data corruption happens. The tool reports the exact position instead, so you can fix the trailing comma or quote yourself in a second.
Why did my big integer change?
JSON numbers are doubles, so integers above 253 lose precision. Store ids as strings, or parse with a library that supports big integers.
Does it support JSON5 or JSONC?
No. This is a strict RFC 8259 parser, which is what APIs and databases expect. Comments and single quotes are rejected with a position pointer.

Related tools