Python json.loads shows ValueError: Extra data

后端 未结 9 927
甜味超标
甜味超标 2020-11-22 16:21

I am getting some data from a JSON file \"new.json\", and I want to filter some data and store it into a new JSON file. Here is my code:

import json
with ope         


        
9条回答
  •  傲寒
    傲寒 (楼主)
    2020-11-22 16:41

    I came across this because I was trying to load a JSON file dumped from MongoDB. It was giving me an error

    JSONDecodeError: Extra data: line 2 column 1
    

    The MongoDB JSON dump has one object per line, so what worked for me is:

    import json
    data = [json.loads(line) for line in open('data.json', 'r')]
    

提交回复
热议问题