Split huge (95Mb) JSON array into smaller chunks?

后端 未结 4 1120
不知归路
不知归路 2021-01-18 06:04

I exported some data from my database in the form of JSON, which is essentially just one [list] with a bunch (900K) of {objects} inside it.

Trying to import it on my

4条回答
  •  心在旅途
    2021-01-18 06:21

    I know this is question is from a while back, but I think this new solution is hassle-free.

    You can use pandas 0.21.0 which supports a chunksize parameter as part of read_json. You can load one chunk at a time and save the json:

    import pandas as pd
    chunks = pd.read_json('file.json', lines=True, chunksize = 20)
    for i, c in enumerate(chunks):
        c.to_json('chunk_{}.json'.format(i))
    

提交回复
热议问题