OmniFeed Search

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:

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:

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.

More in data and formats

Other tools