bitlvl
EN

JSON formatter & validator

Paste JSON. It is validated as you type, with the line and column of the first error and what probably caused it. Then pretty-print, minify, sort or convert it.

What makes JSON invalid

JSON is stricter than JavaScript, and the errors are almost always one of a handful of things:

MistakeWhyFix
{"a": 1,}Trailing commaRemove the comma before } or ].
{'a': 1}Single quotesStrings and keys use double quotes only.
{a: 1}Unquoted keyQuote it: "a".
// commentNo comments in JSONRemove them, or use JSON5 / JSONC where the consumer supports it (VS Code settings, tsconfig).
0123, .5, NaN, InfinityNot valid numbersNo leading zeros, a digit before the point, no NaN/Infinity.
"line\nbreak"Literal newline inside a stringEscape it as \n.
undefinedNot a JSON valueUse null.

Lenient mode strips comments and trailing commas and converts single quotes before parsing, which is handy for config files written by hand. The output is always strict JSON.

YAML

YAML is a superset of JSON in spirit (any JSON document is valid YAML) but far larger: indentation defines structure, strings are usually unquoted, and some bare words have surprising meanings. yes, no, on and off become booleans in YAML 1.1 parsers, 022 may become octal 18, and 3.10 becomes 3.1. The converter quotes such values when emitting YAML so they round-trip. The YAML → JSON direction supports the common block subset: mappings, lists, scalars, quoted strings, flow collections and | / > blocks.

Large documents

Everything runs in your browser, so a few megabytes are fine. The tree statistics (depth, object and array counts) help spot unexpectedly nested data before you load it into something that will choke on it.

Questions

Why is my JSON invalid when it works in JavaScript?

JavaScript object literals allow unquoted keys, single quotes, trailing commas, comments and hex numbers. JSON allows none of them. Turn on lenient mode to see what the strict form would be.

How do I find the error on line 2000 of a big file?

The validator reports the line and column and shows the text around the error. Most editors can jump to a line with Ctrl-G.

Does formatting change the data?

No. Pretty-printing and minifying only change whitespace. Sorting keys changes the order, which JSON does not consider significant, but some consumers (signatures, canonical JSON) do.

Why did a number lose precision?

JavaScript numbers are doubles, so integers above 2⁵³ (about 9 × 10¹⁵) are rounded when parsed. If you format a document with such IDs, store them as strings.