我试图在JSON架构中定义以下内容:
"codenumber": {
"12345": [
{
"prop1": "yes",
"prop2": "no"
}
]
}
codenumber对象包含一个属性" 12345"它始终是包含数组的字符串数字。数值可以改变,所以我不能简单地定义它:
"codenumber": {
"type": "object",
"properties": {
"12345": {
"type": "array",
"items": {
"type": "object",
"properties": {
"prop1": { "type": "string" },
"prop2": { "type": "string" }
}
}
}
}
}
任何方式我都可以将第一个属性名称定义为任何类型的字符串?
答案 0 :(得分:3)
您可以使用" patternProperties"而不是"属性":
"codenumber": {
"type": "object",
"patternProperties": {
"^[0-9]+$": {
"type": "array",
"items": {
"type": "object",
"properties": {
"prop1": { "type": "string" },
"prop2": { "type": "string" }
}
}
}
}
}