如何将JSON模式转换为Avro模式

时间:2019-09-16 23:48:29

标签: json avro jsonschema avro-tools

我的应用程序一直在使用json模式(org.everit.json.schema.Schema)来验证JSON消息是否符合特定格式。我们现在正在考虑转向Avro模式。这涉及将先前存储的schema.json文件转换为要转换为Avro schema schema.avsc的文件。另外,当前行为是我们使用SchemaLoader(例如SchemaLoader.load(JSONObject obj))对其进行验证后,通过API / schema / create获取JSON格式的架构,并将其存储为schema.json格式。

当我们通过API接收运行时时,我们还需要一种将该schema.json转换为schema.avsc的方法。有什么工具或工具可用于将schema.json转换为schema.avsc?

1 个答案:

答案 0 :(得分:0)

在GitHub上查看json-avro-converter。它包括一个简单的命令行界面,用于在Avro和JSON之间进行验证和转换。

使用情况

JSON到Avro
java -jar json2avro-validator.jar -s user.avcs -i user.json

Avro转换为JSON
java -jar json2avro-validator.jar -s user.avcs -i user.avro -m avro2json