JSON Formatter and Validator

Paste raw JSON to pretty-print it, validate it, or minify it for production. Errors are shown with the exact position.

What makes JSON valid

JSON has six value types: object, array, string, number, boolean and null. Objects use string keys in double quotes, arrays hold ordered values, and every element is separated by a comma with no trailing comma allowed after the last one.

The grammar is deliberately strict. Where JavaScript forgives a trailing comma or a single-quoted string, JSON rejects it outright. That strictness is the point: an unambiguous format can be parsed identically by every language, which is why it replaced XML for most APIs.

The five errors that catch almost everyone

A trailing comma after the last property. Single quotes instead of double quotes. Unquoted keys, which is valid JavaScript but not JSON. Comments - JSON has no comment syntax at all. And NaN or undefined, which are JavaScript values with no JSON equivalent; use null instead.

A sixth, subtler one: a byte-order mark at the start of a file saved by some Windows editors. It is invisible and makes the very first character invalid, so the error message points at position 1 and looks nonsensical.

Format or minify

Formatting adds indentation and newlines so a human can read the structure. Two spaces is the common convention; four is also fine as long as it is consistent within a project.

Minifying removes all optional whitespace for transport. It typically cuts payload size by 20-40% with zero change to the data, which matters for API responses and config files shipped to a browser. Keep the pretty-printed version in version control and minify at build time.

Invalid JSON and its fix
InvalidWhyFix
{"a":1,}Trailing comma{"a":1}
{'a':1}Single quotes{"a":"1"}
{a:1}Unquoted key{"a":1}
{"a":1 // note}Comments not allowed{"a":1}
{"a":NaN}NaN is not JSON{"a":null}
{"a":undefined}undefined is not JSON{"a":null}

Frequently asked questions

Why is my JSON invalid?

In order of frequency: a trailing comma, single quotes, an unquoted key, a comment, or NaN/undefined. Validators report the character position, so jump to that offset - the real mistake is usually a few characters before the reported position.

Does this tool fix my JSON automatically?

No, and that is deliberate. It reports the exact position of the error and leaves the fix to you. Automatic repair guesses at intent, and a guess that silently changes a value is worse than a clear error message.

Is there a size limit?

Only what your browser can hold in memory - files of several megabytes format fine. Very large payloads are better handled with jq on the command line, which streams instead of loading everything at once.

Does it support JSON5, JSONC or YAML?

No, only strict RFC 8259 JSON. JSON5 and JSONC allow comments and trailing commas; YAML is a different format entirely. Accepting them here would silently produce output that other systems cannot read.

Is the key order preserved?

Yes, in the order the parser encountered them. Be aware that JSON objects are formally unordered, so no consumer should depend on key order even though every practical parser preserves it.

Everything runs inside your browser. Nothing you type is uploaded, there is no signup, and the page keeps working if you go offline.
Sponsored — ad slot reserved

More free tools

Related guides

Related searches

json formatterjson validatorbeautify json