如何使用不同代码的数据块读取 gzip JSON 文件中的所有数据



我已经压缩了JSON文件,我从Auth0导出,内容如下:

{"Id":"auth0|59bdb71ea714e32e8a6662fd","Nickname":"autoqa.krd0xj","Name":"autoqa.krd0xj@marketingg2.com","Email":"autoqa.krd0xj@marketingg2.com","Email Verified":false,"Connection":"Username-Password-Authentication","Created At":"2017-09-16T23:43:27.002Z","Updated At":"2017-09-16T23:43:27.490Z"},
{"Id":"auth0|18142559","Nickname":"moharvey","Name":"moharvey@ymail.com","Email":"moharvey@ymail.com","Connection":"Username-Password-Authentication","Created At":"2017-08-31T18:55:02.688Z","Updated At":"2017-08-31T19:01:36.994Z"}

我尝试使用此代码:

import json  
import gzip
with gzip.GzipFile("file.gz", 'r') as fin:   
json_bytes = fin.read()                      
json_str = json_bytes.decode('utf-8')            
data = json.loads(json_str)                      
print(data)

但是上面的代码无法读取此文件。 如何读取此文件中的所有数据?我能有一个建议吗?

我刚刚找到了解决方案。我打算删除这个问题,但我没有看到任何这样的问题。

table=[]
with gzip.GzipFile("file.gz", 'r') as fin:   
for line in fin:
table.append(json.loads(line))
for row in table:
print(row)

最新更新