What is the issue with Python while processing my JSON file?

前端 未结 3 1813
余生分开走
余生分开走 2021-01-29 10:56

I have tried to remove the first key and value from a json file using python. While running the program, I came across error, they are mentioned as follows:

imp         


        
3条回答
  •  伪装坚强ぢ
    2021-01-29 11:26

    you have to read the file line by line, since it's rather lines of json data than valid json structure

    Here's my line-by-line proposal

    import json
    data = []
    with open('testing') as f:
        for json_data in f:
           element = json.loads(json_data)  # load from current line as string
           del element['url']
           data.append(element)
    

    Valid json would be in that case:

    [{"url":"example.com","original_url":"http://example.com","text":"blah...blah"...},
    {"url":"example1.com","original_url":"http://example1.com","text":"blah...blah"...}]
    

提交回复
热议问题