JSON formatter and validator
Paste JSON to format or minify it, and if it's invalid, you'll see the line and column where it breaks. The formatter checks strict JSON, so comments, trailing commas, and single-quoted strings count as errors. It runs in your browser; nothing you enter is uploaded.
What strict JSON allows
Two standards define JSON, RFC 8259 and ECMA-404, and both are stricter than JavaScript. Each of these works in a JavaScript object but is an error in JSON:
- a trailing comma, as in
{"a": 1,} - single quotes, as in
{'a': 1}, since strings and keys need double quotes - unquoted keys, as in
{a: 1} - comments, both
//and/* */ NaN,Infinity,undefined, and numbers with leading zeros such as01
Files such as tsconfig.json can have comments because the tools that read them use a looser parser, but the formatter
rejects them. The top level doesn't have to be an object or an array: "hello" and 42 are valid JSON on their own.
Finding the mistake from the error position
The line and column come from your browser's JSON parser. They mark where it gave up, which is often just after the real mistake. In
{"a": 1 "b": 2} the comma is missing after the 1, but the error points at line 1, column 9, the opening quote of
"b". That's where the parser expected a comma or a }. So look at the character before the position as well
as the one at it. Safari's error messages don't include a position, so in Safari you'll see only the message.
What formatting changes
Format and Minify read the JSON into JavaScript values and then write those values out again. That changes more than whitespace:
-
Integers above 253, which is 9007199254740992, lose precision:
12345678901234567890comes out as12345678901234567000. That breaks large numeric IDs, such as 64-bit database keys. - When a key appears twice in one object, only its last value is kept.
-
Keys that look like whole numbers, such as
"1"and"2", move to the front in ascending order, because JavaScript orders object keys that way. Other keys keep their order. 1.0becomes1,1e2becomes100, and an escape such as\u00e9becomes the characteré.
The first two changes lose data. The others keep the meaning, but they show up as changed lines when you diff the result against the original.
Formatting JSON on the command line
jq . data.json # format
jq -c . data.json # minify
python3 -m json.tool data.json # format
For files with 64-bit IDs or numeric keys, use Python's json.tool: it keeps integers of any size exactly and leaves keys in
their original order. In JavaScript, JSON.stringify(value, null, 2) does what the Format button does.