我必须向客户提供上传他自己的 JSON 架构的可能性。
有没有办法验证用户提供的 JSON 模式是有效的 JSON 模式而不仅仅是数据?
我正在使用 Java 和这个库 https://github.com/networknt/json-schema-validator
更新:
我有以下架构:
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "car",
"description": "representation of car",
"type": "object",
"required": [
"id",
"make",
"age",
"model",
"mileage",
"fuel"
],
"properties": {
"id": {
"type": "string"
},
"make": {
"type": "string"
},
"model": {
"type": "string"
},
"age": {
"type": "integer",
"minimum": 0
},
"color": {
"type": "string"
},
"power_in_hp": {
"type": "integer",
"minimum": 0
},
"fuel": {
"enum": ["gasoline", "diesel", "hybrid", "electric"]
},
"mileage": {
"type": "integer",
"minimum": 0
}
}
}
我需要知道这是否是有效的 JSON 架构而不是 JSON 数据。 此处提供了 JSON 数据的示例:
{
"id": "1f5abf56-7210-481a-b2d5-324b6e0f6358",
"make": "Volkswagen",
"model": "Lupo",
"age": 18,
"color": "black",
"power_in_hp": 61,
"fuel": "diesel",
"mileage": 401234
}
最佳答案
是的,您想要根据 JSON Schema meta schema 验证该 JSON .
它将尽可能确保架构有效,但并不是说它有意义或不合逻辑或不可能。
关于java - 验证架构是有效的 JSON 架构而不是数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49533328/