Json 架构,属性 属性 不工作
Json Schema, Properties as Property not working
可能听起来很混乱,我想验证这个模型模式(应该有 $schema、标题、属性和必填字段):
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "My Schema",
"type": "object",
"properties": {
"myData": {
"type": "object",
"properties": {
"name_1": {
"type": "string"
},
"name_2": {
"type": "string"
},
"name_3": {
"type": "string"
}
}
}
},
"required": [
"myData"
]
}
我已经这样做了:
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {
"$schema": {
"type": "string"
},
"title": {
"type": "string"
},
"properties": {
"type": "object",
"enum": "myData"
},
"required": {
"type": "array",
"items": {
"myData": "string"
}
}
}
}
但这部分效果不佳:
"properties": {
"type": "object",
"enum": "myData"
},
可以这样做吗? or 被禁止使用那些构建的模式词,如:"required"、"enum"、"properties" 作为 属性 inside "properties"?。
预先感谢您帮助我理解这部分:)
我的错,对不起。我创建了错误的 json 架构,它应该是这样的:
{
"$schema": "http://json-schema.org/draft-04/schema#",
"id": "http://jsonschema.net",
"type": "object",
"properties": {
"title": {
"type": "string"
},
"type": {
"type": "string"
},
"properties": {
"type": "object",
"properties": {
"myData": {
"type": "object"
}
}
},
"required": {
"type": "array",
"items": {
"type": "string"
}
}
}
}
并且工作正常:)
可能听起来很混乱,我想验证这个模型模式(应该有 $schema、标题、属性和必填字段):
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "My Schema",
"type": "object",
"properties": {
"myData": {
"type": "object",
"properties": {
"name_1": {
"type": "string"
},
"name_2": {
"type": "string"
},
"name_3": {
"type": "string"
}
}
}
},
"required": [
"myData"
]
}
我已经这样做了:
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {
"$schema": {
"type": "string"
},
"title": {
"type": "string"
},
"properties": {
"type": "object",
"enum": "myData"
},
"required": {
"type": "array",
"items": {
"myData": "string"
}
}
}
}
但这部分效果不佳:
"properties": {
"type": "object",
"enum": "myData"
},
可以这样做吗? or 被禁止使用那些构建的模式词,如:"required"、"enum"、"properties" 作为 属性 inside "properties"?。 预先感谢您帮助我理解这部分:)
我的错,对不起。我创建了错误的 json 架构,它应该是这样的:
{
"$schema": "http://json-schema.org/draft-04/schema#",
"id": "http://jsonschema.net",
"type": "object",
"properties": {
"title": {
"type": "string"
},
"type": {
"type": "string"
},
"properties": {
"type": "object",
"properties": {
"myData": {
"type": "object"
}
}
},
"required": {
"type": "array",
"items": {
"type": "string"
}
}
}
}
并且工作正常:)