【发布时间】:2023-02-06 15:43:50
【问题描述】:
以下是 jsonSchema。
{
"$schema": "http://json-schema.org/draft/2020-12/schema#",
"type": "array",
"items": [
{
"type": "object",
"properties": {
"isMerchant": {
"type": "boolean"
},
"isAgent": {
"type": "boolean"
},
"cashLoan": {
"type": "boolean"
},
"personalDetail": {
"type": "string"
},
"contact": {
"type": "object",
"properties": {
"email": {
"type": "string"
},
"mobile": {
"type": "integer"
},
"area": {
"type": "string"
},
"state": {
"type": "string"
}
},
"required": ["state"]}
},
"required": ["isMerchant","cashLoan","contact"],
"allOf": [
{
"if": {
"properties": {
"isMerchant": {"enum": [true]}
}
},
"then": {
"required": [ "isAgent","email","mobile"]
}
},
{
"if": {
"properties": {
"cashLoan": {"enum": [true]}
}
},
"then": {
"required": ["personalDetail"]
}
}
]
}
]
}
预期是使用此 JSON 模式验证相应的 JSON 数据。其中条件如下 -
- 如果“isMerchant”= true,则参数“isAgent”、“email”、“mobile”应该出现在 json 文件中。
- 如果“cashLoan”= true,则参数“personalDetail”应该存在。
【问题讨论】:
标签: json jsonschema json-schema-validator