JSON Formatter

Pretty-print or minify JSON and validate it in one step.

Private by design. Your input never leaves this browser. Conversions run locally on your device.

What this tool handles

  • Pretty-print with 2 or 4 spaces, or minify to a single line.
  • A syntax error reports the line and column and a hint for the usual causes.
  • Key order is preserved, except that keys which are decimal integers move to the front in ascending order — that is how JavaScript objects order their properties.

Example

JSON

{"name":"Ada","ports":[80,443],"active":true}

JSON

{
  "name": "Ada",
  "ports": [
    80,
    443
  ],
  "active": true
}

When you would use it

  • Reading a response copied from devtools — Paste the single-line body you copied from the Network tab and get an indented document you can actually scan for the field you were looking for.
  • Packing JSON into an environment variable — Minify a service-account blob or a config object so it fits on one line in a .env file or a CI secret that only accepts a single value.
  • Finding the error in a hand-edited tsconfig — When a build fails with a bare parse error, this reports the line and column of the trailing comma or unquoted key that caused it.
  • Normalising a fixture before review — Re-indent a committed JSON fixture to 2 or 4 spaces so the next diff shows the values that changed rather than the whitespace.

Common questions

What happens to duplicate keys?

The last one wins and the earlier value is discarded without a warning, which is what JSON.parse does. {"a":1,"a":2} formats as {"a": 2}.

Will a large ID keep all its digits?

No. Numbers are parsed as IEEE-754 doubles, so an integer past 2^53 is rounded, 1.0 prints as 1 and -0 prints as 0. Keep IDs of that size as strings.

Does it accept comments or trailing commas?

No, the input has to be strict JSON. Comments, single-quoted keys, trailing commas, NaN and several documents pasted one after another are all reported as errors with a position.

Related tools

Browse all 25 tools