schema = { "type" : "object",
"properties" :
{ "price" : {"type" : "array",
"items" : { "type" : "string" , "pattern": "^[A-Za-z0-9_]*$" }},
},
}
from jsonschema import validate
validate(instance={"price" : ["test","34"]}, schema=schema)
上面的代码验证了具有非间隔字符串数组项的属性价格。即使我们不知道传入的属性名称,是否可以验证该属性?
可能像下面这样
schema = { "type" : "object",
"properties" :
{ "type" : "array",
"items" : { "type" : "string" , "pattern": "^[A-Za-z0-9_]*$" },
},
}
from jsonschema import validate
validate(instance={"price" : ["test","34"]}, schema=schema)
validate(instance={"marks" : ["test","34"]}, schema=schema)