Reputation: 683
My Json data looks like
{
"key1": "value1",
"key2": "value2",
"key3": "value3",
"iterKey": {
"key11": ["val11", "val12"],
"key21": ["val21"],
"key31": ["val31","val32"] }
}
In above Json data key1, key2 and key3 is fixed and its value is string. But iterKey is a Map which contains key value pair. The size and value of iterKey is not fixed. I want to write Json schema which will validate that all keys (key11, key21, key31 ..etc) are string and their value is list of strings.
(I dont know value of key11, key21 ..etc, it could be any value) Please help to write schema for this type of JSON data.
Upvotes: 1
Views: 775
Reputation:
Use patternProperties
instead of properties
. Then, the keys are not objects but regular expressions. Use .*
as regular expression to match everything.
{
"type": "object",
"properties": {
"key1": {
"type": "string"
},
...
"iterKey": {
"type": "object",
"patternProperties": {
".*": {
"type": "array",
"items": {
"type": "string"
}
}
}
}
}
}
Upvotes: 1