The mistakes that break JSON
JSON is strict. These are the errors we see most, and the validator points to the line and column of each:
- Trailing commas.
[1, 2, 3,]is fine in JavaScript and Python but invalid in JSON. - Single quotes. Strings and keys must use double quotes:
{"name": "Pico"}, not{'name': 'Pico'}. - Unquoted keys.
{name: "Pico"}is a JavaScript object, not JSON. - Comments. JSON has no comments at all.
- Python values.
True,FalseandNonemust betrue,falseandnull. Usejson.dumps()rather thanstr()to turn a Python dictionary into JSON. - Raw line breaks inside strings. Write them as
\n.
Formatting and minifying
Formatting adds line breaks and indentation so people can read the structure. Minifying removes every unneeded space to make the data smaller to send. Both produce identical data. In Python, json.dumps(data, indent=2) formats and json.dumps(data, separators=(",", ":")) minifies.
New to JSON? JSON for beginners explains objects, arrays and how AI APIs use them.