Python can't parse JSON with extra trailing comma

前端 未结 6 910
梦如初夏
梦如初夏 2020-12-21 03:59

This code:

import json
s = \'{ \"key1\": \"value1\", \"key2\": \"value2\", }\'
json.loads(s)

produces this error in Python 2:

6条回答
  •  余生分开走
    2020-12-21 04:27

    I suspect it doesn't parse because "it's not json", but you could pre-process strings, using regular expression to replace , } with } and , ] with ]

提交回复
热议问题