Google Big Query 表无法使用 JSON 文件创建

问题描述 投票:0回答:1

使用云存储中上传的 json 文件在 Google Big 查询中创建表时出现以下错误。 创建表失败:读取数据时出错,错误消息:无法解析 JSON:字符串意外结束;字符串意外结束;预期密钥文件:GCP_Cloud_Storage_HR_Analytics_POC-Changed_data_14-07[1].json

我知道我们 BQ 需要新的分隔 Json 文件,但是有没有办法将 JSON 转换为新的分隔 Json,因为记录计数更多,我无法手动更改它

非常感谢任何帮助

使用云存储中上传的 JSON 文件成功在 Big Query 中创建表

json google-bigquery google-cloud-storage
1个回答
0
投票

尝试这个代码。

它使用 ndjson python 包,您可以按照说明安装https://pypi.org/project/ndjson/0.3.1/

import ndjson
import json

    # with open('your_input_path_to_json_file/ndjson.json') as f:
    #     data = json.loads(f)
    input = '[{"a":1,"b":2,"c":3},{"x":4,"y":5,"z":6}]'
    data = json.loads(input)
    with open('your_output_path_to_newline_delimted/backup.ndjson', 'w') as f:
        ndjson.dump(data, f)

如果您不想编写代码,请尝试这个在线转换器https://www.json-to-ndjson.app/

© www.soinside.com 2019 - 2024. All rights reserved.