JSON Formatter & Validator
Format, minify and validate JSON — with the error pointed at, not just reported.
Parsing happens in your browser and nothing is uploaded — worth knowing when the file is an API response with credentials or customer records in it.
How it works
Formatting JSON is trivial. Finding out why a 4,000-line file will not parse is not, and that is what this is actually for.
A browser's own parser reports errors like "Unexpected token } in JSON at position 2847", which tells you the offset and nothing about where that is. This converts the offset into a line and column, shows you the offending line with the position marked, and adds a plain-English guess at the cause — a trailing comma, a single quote where JSON requires a double, an unquoted key, a stray comment, or the `NaN` your serialiser emitted for a number that was not one.
Those five account for the overwhelming majority of invalid JSON, and four of them exist because JSON looks like JavaScript and is much stricter than it. JSON has no comments, no trailing commas, no single-quoted strings, no unquoted keys, and no `undefined`, `NaN` or `Infinity`. Anything that produced those was writing JavaScript, not JSON.
The statistics underneath are there because they answer the question you usually have next: how deep does this nest, how many keys are there, how big is the largest array, and is there a duplicate key hiding in it. Duplicate keys are technically legal and silently resolved last-one-wins by every parser, which makes them one of the harder configuration bugs to see by eye.
Sorting keys is for diffing. Two exports of the same data with keys in different orders produce a diff full of noise; sorted, the real change is the only thing left.
Common questions
Why is my JSON invalid when it looks fine?
Almost always one of five things: a trailing comma after the last item, single quotes instead of double, an unquoted key, a comment, or NaN and Infinity from a serialiser. JSON resembles JavaScript but forbids all of these.
Does it change my numbers?
Reformatting round-trips through the browser's parser, which stores numbers as 64-bit floats. Anything beyond about 9 quadrillion — long database identifiers and Twitter-style snowflake IDs are the usual victims — loses precision. If your file has those, they should have been strings, and reformatting will quietly corrupt them.
What does sorting the keys do to arrays?
Nothing. Array order is meaningful in JSON and is always preserved. Only object keys are reordered, and only because object key order is not supposed to carry meaning.
Can it handle a large file?
Comfortably into tens of megabytes. The limit is your browser's memory rather than anything here, and the whole file has to be held twice — once parsed, once as output text.