pythonjsonmalformed

Parsing "JSON" containing trailing commas


Are there any Python JSON parsers that will cope with trailing commas?

(I'm consuming the "JSON" from an external source and have no control over it.)


Solution

  • Grab PyYAML. JSON is a subset of YAML, so a YAML parser should parse most JSON. YAML's grammar allows trailing commas in sequences.