Parsing a string with json.loads() fails because the string does not conform to valid JSON format.
Raised when the built-in json module's loads() or load() function encounters syntax errors while parsing a text payload (like unquoted keys, single quotes, or trailing commas).
Trying to parse empty strings, parsing single-quoted strings, or receiving HTML error pages from an external web API instead of JSON.
1import json2 3# Bug: Invalid JSON syntax (single quotes, trailing comma)4bad_json = "{'name': 'Bob', 'age': 30,}"5data = json.loads(bad_json) # json.decoder.JSONDecodeError1import json2 3# Fix 1: Correct JSON format (double quotes, no trailing comma)4good_json = '{"name": "Bob", "age": 30}'5data = json.loads(good_json) # Successfully parsed!6 7# Fix 2: Catch JSONDecodeError safely8payload = "invalid data"9try:10 config = json.loads(payload)11except json.JSONDecodeError as e:12 print(f"JSON parsing failed: {e.msg} at line {e.lineno}")Simulate standard system builds to trigger compiler trace records and track memory crashes locally.
The JSON specification mandates double quotes for strings and keys, and forbids trailing commas. json.loads() fails to parse bad_json and raises JSONDecodeError.