【发布时间】:2019-10-06 02:04:07
【问题描述】:
我有一个带有 gzip 文件 (.json.gz) 的 json 压缩文件,存储在 Google Cloud Storage 的存储桶中,我想在其中读取它并将其复制到 postgres 表中。我拥有的 json.gz 文件只是一个没有嵌套对象的 json 文件,如下所示:
[{
“date”: “2019-03-10T07:00:00.000Z”,
“type”: “chair”,
“total”: 250.0,
"payment": "cash"
},{
“date”: “2019-03-10T07:00:00.000Z”,
“type”: “shirt”,
“total”: 100.0,
"payment": "credit card"
},{
.
.
}]
以前我用 csv 文件做过类似的工作,我可以在其中使用 download_as_string 函数并将其存储在变量中,并使用 StringIO 将该变量转换为类似文件的对象,并将 copy_expert() 函数与查询一起使用(this link)。
那么,如何在 GCS 中读取 json.gz 文件并使用 Python 将其写入表中?
【问题讨论】:
标签: python json postgresql google-cloud-storage gzip