JSON's Grammar and Origins

JSON's Grammar and Where It Came From

Douglas Crockford and Chip Morningstar sent the first JSON message in April 2001, reusing JavaScript's object-literal syntax. RFC 4627 (2006) described it; ECMA-404 (second edition, 2017) and RFC 8259 (December 2017, STD 90) are the current, matching definitions. A JSON text is one value: object, array, string, number, true, false or null. There are no comments, trailing commas, single quotes, leading zeros, NaN or Infinity, and no date, decimal or binary type; dates travel as ISO 8601 strings and bytes as Base64 by convention only. Parsers may accept extensions, and Python does:

Which texts does Python's json module accept?JavaScript
import json
for text in ['{"id": 1,}', "{'id': 1}", '{"price": 014.99}', '{"price": NaN}']:
    try:
        print("accepted", text, json.loads(text))
    except json.JSONDecodeError as err:
        print("rejected", text, "-", err.msg)
Output
rejected {"id": 1,} - Illegal trailing comma before end of object
rejected {'id': 1} - Expecting property name enclosed in double quotes
rejected {"price": 014.99} - Expecting ',' delimiter
accepted {"price": NaN} {'price': nan}

Python also writes NaN by default, producing files that JSON.parse and Go's encoding/json reject, so pass allow_nan=False to json.dumps. Keep JSON5 and JSONC (JSON with comments) in configuration, never in data.