我有以下json数据对象:
{
"name": "John",
"favorite_number": 5,
"favorite_color" : "green"
}
此对象的JSON架构如下所示:
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Person",
"description": "some description",
"type": "object",
"properties": {
"name": {
"description": "name",
"type": "string"
},
"favorite_number": {
"type": "number",
},
"favorite_color": {
"type": "string",
},
},
"required": ["name", "favorite_number","favorite_color"]
}
我可以使用这个JSON模式来验证我的数据对象是否符合它:
public static boolean isJsonValid(String schemaText, String jsonText) throws ProcessingException, IOException
{
final JsonSchema schemaNode = getSchemaNode(schemaText);
final JsonNode jsonNode = getJsonNode(jsonText);
return isJsonValid(schemaNode, jsonNode);
}
在我的java应用程序中,我从REST API调用接收到此对象的相应AVRO架构,该架构如下所示:
{
"namespace": "example.avro",
"type": "record",
"name": "Person",
"fields": [
{"name": "name", "type": "string"},
{"name": "favorite_number", "type": ["int", "null"]},
{"name": "favorite_color", "type": ["string", "null"]}
]
}
是否有一种通常可接受的方式将此类AVRO架构转换为JSON架构?
答案 0 :(得分:0)
avro-tools-1.7.4.jar
(或最新版本from repository)java -jar avro-tools-1.7.4.jar tojson avro-filename.avro>output-filename.json
这将create output-filename.json
文件包含所有数据。如果output-filename.json
已经存在,则会覆盖它。