toolfree

JSON formatter

Format, minify and validate JSON in your browser. Reports the line and column of a syntax error, sorts keys, and never uploads what you paste.

Runs in your browser

Formatting and validating are the same operation

There is no way to indent JSON without parsing it first, so anything that pretty-prints your document has already told you whether it is valid. The formatter above re-runs on every keystroke: as long as the output pane is filling in, the document parses.

When it does not, the message names the line and column where the parser gave up. That position is where the error was detected, not always where it was made — a missing comma on line 12 is usually reported at the start of line 13, because that is the first token that cannot follow what came before.

The four things that are not valid JSON

Most “invalid JSON” is valid JavaScript, which is the whole confusion. JSON is a strict subset:

Written asWhy it fails
{name: "x"}Keys must be double-quoted strings
{'name': 'x'}Single quotes are not string delimiters in JSON
{"a": 1,}Trailing commas are a syntax error
// a noteJSON has no comments, in any position

NaN, Infinity and undefined are also absent — they are JavaScript values with no JSON representation. A number in JSON is a finite decimal, optionally with an exponent.

Large integers do not survive a round trip

JSON.parse produces JavaScript numbers, which are IEEE-754 doubles. Integers above 2^53 − 1 (9007199254740991) lose precision silently:

JSON.parse('{"id": 9007199254740993}').id  // 9007199254740992

Twitter/X snowflake IDs, Discord IDs, and 64-bit database keys all land in this range, which is why APIs that use them serialise the id as a string. If reformatting a document changes an id by one, this is why — and it is the parser, not the formatter. Keep such values quoted.

Sorting keys

Object key order is not meaningful in JSON, but it is preserved by every parser in practice. Sorting both sides of a comparison is the cheapest way to diff two documents that carry the same data in a different order. Array order is left alone: that ordering is data.

Your data stays here

Parsing and printing happen in your browser. Nothing you paste is sent anywhere, which matters more for JSON than for most formats — API payloads routinely carry tokens, personal data, and internal identifiers.