Check

Format and check JSON

Indent it, or find out where the parser stopped.

The check is the browser’s own JSON parser, not a re-implementation, so anything it accepts is JSON that every other parser accepts too. Formatting re-serialises the parsed value with two spaces of indentation.

When the input is invalid, the result is the parser’s own message, word for word. Some errors come with a position and some do not — browsers vary, and Chrome can name the offending token without a character offset — but the reason it stopped is always more use than a generic “invalid JSON”.

A round trip through the parser also removes what JSON does not have: comments, trailing commas, and duplicate keys where the last one wins. A file that relied on a duplicate key will keep only one value here — which is what any consumer of that file would have seen anyway.

Questions

Does it accept comments or trailing commas?

No. JSON allows neither and neither does this parser. That is why a file that loads inside a JavaScript file can still fail here: a JavaScript object literal is not JSON.

Will it repair my broken JSON?

No. It tells you why the parser stopped; the fix is yours. Guessing at a repair would be worse than the error.

Is the JSON uploaded?

No. The parse happens in the tab and nothing is stored.

Why did a duplicate key disappear?

JSON objects have unique keys. The parser keeps the last one, and that is what every consumer of the file sees.

More text and code