Skip to content
Popular tools

2026-08-12

How to format JSON without losing data

Pretty printing JSON only changes whitespace. If the input is valid, the formatted document represents the same values: the same strings, numbers, booleans, nulls, arrays, and objects. You are not “fixing” the data. You are making the structure readable.

What a formatter actually does

A formatter parses the text into a JSON value, then serializes it again with indentation. That means comments, trailing commas, and single quotes disappear the hard way: they are rejected before anything is printed. If you need those dialects, you are not looking at JSON.

{"name":"Ada","roles":["engineer","mathematician"]}

becomes:

{
  "name": "Ada",
  "roles": [
    "engineer",
    "mathematician"
  ]
}

When you should minify instead

Use pretty print to read. Use minify to embed a payload in a command, a CI variable, or a compact log line. Minifying is still not gzip. It only removes whitespace that parsers ignore.

Errors that block formatting

  • Missing commas between properties or array items
  • Trailing commas after the last item
  • Unquoted keys, which JavaScript allows and JSON does not
  • Single quotes around strings
  • Unescaped newlines inside strings

Alphzen’s JSON Formatter reports the first parse error with a line and column. Fix that location, then format again. Do not trust a tool that “formats” invalid JSON into something that looks pretty but is no longer the original document.