Glossary Data & Encoding

JSON

JSON (JavaScript Object Notation) is a lightweight text format for structured data, built from objects, arrays, strings, numbers, true, false and null.

Last reviewed:

AdSense Placeholder
Slot: header_reference_page

In more detail

A JSON document is one value: an object ({} with string keys), an array ([]), a string, a number, true, false or null. Keys and strings must use double quotes, and comments and trailing commas are not allowed, which are the usual causes of "invalid JSON" errors. Numbers cannot have leading zeros, and NaN and Infinity are not valid. Text must be Unicode, in practice UTF-8. JSON is the usual format for web APIs and many configuration files. See How JSON Works.

Why it matters

The format sets no limit on number size, but JavaScript reads all numbers as 64-bit floats, so integers above 9,007,199,254,740,991 silently lose precision: 9007199254740993 is read back as 9007199254740992. Large IDs are therefore often sent as strings. Duplicate keys are syntactically allowed but parsers disagree on which one wins.

Example

{"name": "Ana", "age": 30, "tags": ["a", "b"], "active": true, "manager": null} is valid. A JavaScript-style literal is not:

>>> json.loads("{'name': 'Ana',}")
json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 1 column 2 (char 1)

Common confusion

JSON looks like a JavaScript object literal but is stricter; YAML is a superset-like format that allows comments and unquoted strings.

AdSense Placeholder
Slot: footer_leaderboard