如何将json模式转换为avro模式 [英] How to convert json schema to avro schema

查看:592
本文介绍了如何将json模式转换为avro模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序一直在使用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格式.

My application has been using json schema (org.everit.json.schema.Schema ) to validate JSON messages whether they comply to a particular format. We are now thinking of moving to the Avro schema. This involves converting previously-stored schema.json files to be converted to Avro schema schema.avsc. Also, the current behavior is we get schema in JSON format via an API /schema/create and store it schema.json format after validating it using SchemaLoader, for example, SchemaLoader.load(JSONObject obj).

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

We also need a way to convert this schema.json to schema.avsc as we receive it run time via API. Is there any utility/tool we can use to convert the schema.json to schema.avsc?

推荐答案

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

Take a look at json-avro-converter on GitHub. It includes a simple command line interface for validating and converting between Avro and JSON.

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

JSON to 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

Avro to JSON
java -jar json2avro-validator.jar -s user.avcs -i user.avro -m avro2json

这篇关于如何将json模式转换为avro模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆