有以下json数据,该数据的schema怎么写
{
"xiaoming":{
"age":"18",
"score":20
},
"xiaohong":{
"age":"10",
"score":99
},
"xiaolang":{
"age":"11",
"score":210
}
}
"xiaoming","xiaohong","xiaolang"是不确定的,会是任意字符串,然后age和score是每个人必须要有的
你可以使用patternProperties
参考
https://json-schema.org/understanding-json-schema/reference/object.html#id4
{
"type": "object",
"patternProperties": {
"^[a-zA-Z]+$": {
"type": "object",
"required": ["age", "score"],
"properties": {
"age": {
"type": "string"
},
"score": {
"type": "number"
}
}
}
},
"additionalProperties": false
}