The errors that make JSON invalid
| Invalid | Valid |
|---|---|
| {"a": 1,} | {"a": 1} |
| {'a': 1} | {"a": 1} |
| {a: 1} | {"a": 1} |
| {"a": 1 // note} | {"a": 1} |
| {"a": undefined} | {"a": null} |
| {"a": 1 "b": 2} | {"a": 1, "b": 2} |
Repair fixes the first four. The last two need a person: there's no safe guess for what undefined or a missing comma meant.
Format JSON from the command line
python3 -m json.tool data.json works on any Mac, and jq . data.json if you have jq. In JavaScript, JSON.stringify(value, null, 2) pretty-prints with 2 spaces.
