Using python ijson to read a large json file with multiple json objects

前端 未结 2 1101
走了就别回头了
走了就别回头了 2021-02-19 07:45

I\'m trying to parse a large (~100MB) json file using ijson package which allows me to interact with the file in an efficient way. However, after writing some code like this,

2条回答
  •  隐瞒了意图╮
    2021-02-19 08:12

    Since the provided chunk looks more like a set of lines each composing an independent JSON, it should be parsed accordingly:

    # each JSON is small, there's no need in iterative processing
    import json 
    with open(filename, 'r') as f:
        for line in f:
            data = json.loads(line)
            # data[u'name'], data[u'engine_speed'], data[u'timestamp'] now
            # contain correspoding values
    

提交回复
热议问题