我想知道如何使用随机名称验证子属性中的“haha”?
{
"shipping_address": {
"randomName1":{
"haha":"ddd"},
"randomName2":{
"haha":"ddd"},
"randomName3":{
"haha":"ddd"},
}
}
我试图简单地使用 allOf,但我的不起作用:
{
"$schema": "http://json-schema.org/draft-6/schema#",
"type": "object",
"properties": {
"shipping_address": {
"allOf": [
{ "properties":
{ "haha": { "type": "integer" } }
}
]
}
}
}
你可以在这里试一试:https : //www.jsonschemavalidator.net/
使用模式属性
{
"$schema": "http://json-schema.org/draft-6/schema#",
"type": "object",
"properties": {
"shipping_address": {
"patternProperties": {
"^.*$": {
"properties": {
"haha":{
"type":"integer"
}
}
}
}
}
}
}
正如 vearutop 评论的那样,改进版本:
{
"$schema": "http://json-schema.org/draft-6/schema#",
"type": "object",
"properties": {
"shipping_address": {
"additionalProperties":{
"properties":{
"haha":{
"type":"integer"
}
}
}
}
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句