【发布时间】:2021-05-27 01:53:05
【问题描述】:
我试图转换为模式的 JSON 示例是:
{
"nodeID": "5f9f5dbe0c3ab520c2b44bb0",
"type": "block",
"coords": [
517.2814214277396,
769.7697271579176
],
"data": {
"name": "Block",
"color": "standard",
"steps": [
"5f9f5dbe0c3ab520c2b44bb1"
]
}
}
我已将其转换为此架构
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {
"nodeID": {
"type": "string"
},
"type": {
"type": "string"
},
"data": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"intent": {
"type": "string"
},
"diagramID": {
"type": "string"
},
"mappings": {
"type": "array",
"items": {}
},
"next": {
"type": "null"
},
"ports": {
"type": "array",
"items": {}
}
},
"required": [
"name",
"intent",
"diagramID",
"mappings",
"next",
"ports"
]
}
},
"required": [
"nodeID",
"type",
"data"
]
}
在示例 JSON 中,您可以看到 type = "block"。 我如何在架构中确保在检查 JSON 时确保检查类型键是否为 == "block"?
谢谢! :)
【问题讨论】:
标签: json validation schema jsonschema json-schema-validator