Can json.loads ignore trailing commas?

后端 未结 4 1492
眼角桃花
眼角桃花 2020-12-01 20:33

As mentioned in this StackOverflow question, you are not allowed to have any trailing commas in json. For example, this

{
    \"key1\": \"value1\",
    \"key         


        
4条回答
  •  庸人自扰
    2020-12-01 21:22

    You can wrap python's json parser with jsoncomment

    JSON Comment allows to parse JSON files or strings with:

    • Single and Multi line comments
    • Multi line data strings
    • Trailing commas in objects and arrays, after the last item

    Example usage:

    import json
    from jsoncomment import JsonComment
    
    with open(filename) as data_file:    
        parser = JsonComment(json)
        data = parser.load(data_file)
    

提交回复
热议问题