Retrieving JSON objects from a text file (using Python)

后端 未结 9 1605
失恋的感觉
失恋的感觉 2020-11-30 04:50

I have thousands of text files containing multiple JSON objects, but unfortunately there is no delimiter between the objects. Objects are stored as dictionaries and some of

9条回答
  •  盖世英雄少女心
    2020-11-30 05:31

    import json
    
    file1 = open('filepath', 'r')
    data = file1.readlines()
    
    for line in data :
       values = json.loads(line)
    
    '''Now you can access all the objects using values.get('key') '''
    

提交回复
热议问题