data
parsing
ai_generated
true
json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes at trailing comma
ID: data/json-trailing-comma-parse-error
92%Fix Rate
95%Confidence
3Evidence
2023-01-01First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| any | active | — | — | — |
Root Cause
Trailing commas are valid in JavaScript but invalid in JSON (RFC 8259). Many developers write JSON by hand or copy from JS and include trailing commas. JSON.parse and json.loads both reject them.
genericWorkarounds
-
90% success Use json5 library for human-written config files that need comments/trailing commas
import json5; data = json5.load(open('config.json5')) # allows trailing commas, comments -
82% success Strip trailing commas with regex before parsing (for trusted input only)
import re; clean = re.sub(r',\s*([}\]])', r'\1', json_str); data = json.loads(clean)
-
88% success Use a linter (jsonlint) to validate JSON before processing
npx jsonlint file.json # or: python -m json.tool file.json
Dead Ends
Common approaches that don't work:
-
Allow trailing commas because JSON is 'just JavaScript object notation'
95% fail
JSON is NOT JavaScript. JSON is a strict subset. Trailing commas, single quotes, unquoted keys, and comments are all invalid JSON.
-
Use eval() or Function() to parse JSON with trailing commas
98% fail
eval() is a critical security vulnerability for untrusted data. Never use eval() to parse JSON.