Free Handy Tools

JSON Formatter & Validator

Formatting, validating and finding the break

JSON arrives minified from an API, hand-edited into a config file, or pasted out of a log, and in all three cases the first thing you need is to see its shape. This tool re-indents JSON at two spaces, four spaces or a tab, minifies it back down, and tells you immediately whether it parses at all — reformatting as you type rather than waiting for a button, so the output can never sit there contradicting the input.

When it does not parse, it reports the problem by line and column with a description of what was expected, which is the part that saves the time.

Error messages you can act on

The browser’s own JSON errors are inconsistent. Most carry a character offset — "Unexpected number in JSON at position 32" — which means counting characters in a 40-line file, and some carry no position at all. The wording also changes between browser releases, so the same broken file produces different messages in different places.

This tool locates the fault itself and reports it in editor coordinates. A file whose third line reads "value": 01 is answered with “Expected "," or "}" after property value (line 3, column 13)” — the leading zero is illegal in JSON, so the parser gave up on the number and wanted a delimiter. A trailing comma in {"a": 1,} gives “Trailing comma before "}" (line 1, column 9)”. A key written in single quotes gives “Expected a double-quoted property name (line 1, column 2)”. An unrecognised escape such as \q inside a string gives “Invalid escape "\q" (line 1, column 10)”.

What JSON allows, and what it does not

Most invalid JSON is valid JavaScript, which is why it looks fine. The specification is much stricter than the language it came from:

  • Keys must be double-quoted strings. Bare keys and single quotes are both rejected.
  • No trailing comma is permitted before a closing brace or bracket.
  • No comments of any kind. // and /* */ are JavaScript, not JSON.
  • Numbers may not have a leading zero, a leading plus, or a bare decimal point: 01, +1 and .5 are all invalid, while 0.5 and 1e-3 are fine.
  • undefined, NaN and Infinity are not JSON values. Only strings, numbers, true, false, null, objects and arrays are.

How it behaves, and what it does not do

Validation is done by the browser’s own parser, so a document accepted here is accepted by anything else that follows the specification. Formatting is re-serialisation, not text manipulation: the document is parsed to values and printed again. That has one consequence worth knowing — key order is preserved, but the original whitespace, and any duplicate key, is not. Where a key appears twice, the last one wins, which is the same rule every JSON parser applies.

Everything happens in your browser. Nothing is uploaded, logged or stored, which matters given how often the JSON someone needs to inspect contains a token, a customer record or a payload from production. There is no schema validation, no JSON5 or JSONC support, and no repair mode: the tool tells you precisely where the document breaks, and leaves fixing it to you.

JSON questions

Why is my trailing comma an error?

Because JSON does not allow one, even though JavaScript does and most editors will not flag it. It is the single most common cause of a file that looks correct and will not parse — particularly after deleting the last entry from a list.

Can I add comments to a JSON file?

Not in JSON itself. The usual workarounds are a dedicated key such as "_comment", or a superset like JSON5 or JSONC — the latter is what VS Code accepts in its own settings files. Neither will parse as plain JSON, so anything consuming the file has to know.

What indentation should I use?

Two spaces is the most common convention for JSON and is what most formatters emit by default. Minify for anything transmitted over a network, where whitespace is pure overhead, and indent for anything a person has to read or diff.