我希望能够使用类似于“hdfs -text *.avro”但在 Google 云存储中的内容将 avro 文件读取为 json。我将在 python 脚本中解析 json
我正在寻找一种 gsutil 命令方式来将 avro 文件读取为 json,类似于我们在 hdfs 中的做法
没有直接的方法来读取 Avro 文件
如何在 Google Cloud Storage 中读取 Avro 文件作为 JSON 文本:
avro-tools
命令。gsutil cat gs://<bucket>/<path/to/avro/file.avro> | avro-tools tojson > <path/to/json/file.json>
这将从 Google Cloud Storage 读取 Avro 文件,将其转换为 JSON,并将 JSON 输出写入指定文件。
json
模块)解析 Python 脚本中的 JSON 文件。这是解析 JSON 文件的 Python 脚本示例
my-json-file.json
:
import json
with open("my-json-file.json", "r") as f:
json_data = json.load(f)
# Iterate over the JSON data and do something with it
for record in json_data:
print(record)