简体   繁体   English

JSON 到 Avro 转换 Python 无架构

[英]JSON to Avro conversion Python without schema

i have a generic json file {"name":"foo","age":20}.我有一个通用的 json 文件 {"name":"foo","age":20}。 I need to convert it in avro format in python 3.x.我需要在 python 3.x 中将其转换为 avro 格式。 I tried using fastavro and avro-python3 but both libraries asking for schema.我尝试使用 fastavro 和 avro-python3,但两个库都要求提供模式。 Is there any way to generate avro without schema?有没有办法在没有模式的情况下生成 avro?

The below code works fine.下面的代码工作正常。 But I am not able to generate without schema.但我无法在没有模式的情况下生成。

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()

either in your worker config, or your new connector config在您的工作人员配置或新的连接器配置中


key.converter.schemas.enable=false
value.converter.schemas.enable=false


声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在没有架构的情况下将 json 转换为 avro? - How to convert a json to avro without a schema? 在没有 AVRO 架构的情况下反序列化 Python 中的 Avro Object - Deserialize Avro Object In Python Without Having AVRO Schema On Hand 将json解析为avro模式时出现Python异常:avro.schema.SchemaParseException:没有“ type”属性 - Python exception while parsing json to avro schema: avro.schema.SchemaParseException: No “type” property 如何在没有架构的情况下使用 python 生成 avro 类型? - How can I produce without schema as avro type with python? 带有(反)序列化器和模式验证的Python JSON REST框架(jsonschema / avro) - Python JSON REST framework with (de)serialiser and schema validation (jsonschema/avro) 为 python dict 创建 avro 模式 - Create avro schema for python dict Avro Producer 发送没有密钥架构的密钥 - Avro Producer sending key without key schema Python 使用 AVRO 的 Kafka 消费者消息反序列化,没有模式注册表 - 问题 - Python Kafka consumer message deserialisation using AVRO, without schema registry - problem Python 3.4和AVRO:无法基于模式在AVRO中转换简单消息? - Python 3.4 and AVRO: Unable to convert the simple message in AVRO, based on schema? Python Avro avro.io.AvroTypeException 数据不是架构示例 - Python Avro avro.io.AvroTypeException The datum is not an example of schema
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM