[英]JSON to Avro conversion Python without schema
我有一個通用的 json 文件 {"name":"foo","age":20}。 我需要在 python 3.x 中將其轉換為 avro 格式。 我嘗試使用 fastavro 和 avro-python3,但兩個庫都要求提供模式。 有沒有辦法在沒有模式的情況下生成 avro?
下面的代碼工作正常。 但我無法在沒有模式的情況下生成。
import avro.schema
import json
from avro.datafile import DataFileReader, DataFileWriter
from avro.io import DatumReader, DatumWriter
schema = avro.schema.Parse(open("C:\\wwm\\schema2.avsc").read())
print(schema)
with open("C:\\wwm\\data.json") as js:
x=json.load(js)
writer = DataFileWriter(open("C:\\wwm\\data.avro", "wb"), DatumWriter(),schema)
writer.append(x)
writer.close()
在您的工作人員配置或新的連接器配置中
key.converter.schemas.enable=false
value.converter.schemas.enable=false
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.