JSON Formatter / Minifier

How do I format JSON?

How it is calculated

The tool parses the text as JSON and writes it back out in one of two layouts. In minify mode all optional whitespace is removed, giving the shortest valid text. In pretty mode it adds line breaks and four-space indentation, one key per line. If the text is not valid JSON, for example it has single quotes, a trailing comma or an unquoted key, the tool shows an invalid message instead of guessing a fix. Keys keep their original order and every value is kept exactly as typed: {} stays {}, 1.0 stays 1.0, big integers keep all their digits, and strings are copied with their escapes unchanged. Empty input returns nothing.

Worked example

Input: { "name": "Ada", "age": 36 } with mode set to minify. The text is valid JSON: an object with two keys. The spaces after the braces, colons and commas are not needed, so they are removed. The output is {"name":"Ada","age":36}, 23 characters instead of 28. In pretty mode the same data would be printed on four lines with indentation.

Try this example →

Common mistakes

  • Pasting JavaScript object syntax such as {name: 'Ada'}. JSON needs double quotes around keys and strings.
  • Leaving a trailing comma after the last item, which is invalid and gives an error.
  • Expecting the tool to repair broken JSON. It only reports it as invalid.
  • Minifying a file that contains comments. Standard JSON has no comments, so it fails to parse.

About this calculator

This tool takes a block of JSON text and either pretty-prints it — adding indentation and line breaks so nested objects and arrays are readable — or minifies it down to a single compact line, and it flags syntax errors like a missing comma or an unclosed bracket that would otherwise make the JSON fail to parse.

Developers use the pretty-print side constantly when inspecting an API response, a config file, or a webhook payload that arrives as an unreadable single-line string, and use the minify side when preparing JSON to ship in production — smaller payloads mean less bandwidth and faster load times. It's also a fast way to check whether a hand-edited config file or a copy-pasted API response is actually valid JSON before it causes a parsing error somewhere else in the code.

Was this helpful?

You can pick up to 3 reactions.

Comments (1)

  • Editorial team

    When the tool reports invalid JSON, it does not say where the problem is. A reliable way to find it is to cut the text in half, test each half as its own piece, and repeat on the half that fails. The text is processed on our server, so remove passwords, API tokens and personal data before pasting anything. Which kind of JSON do you format most often: API responses, config files or logs?

Popular calculators

All Calculators