Reputation: 48899
I want to constrain my object values. In particular, only string
and array
(of string) types are allowed:
"myobject": {
"string": "foo",
"array": [
"bar",
"baz",
],
"bool": true, // invalid
"object": {}, // invalid
}
Object keys should be "free". I can't find a way to do this in JSON schema.
The following seems not working, it still allow bool
and object
value types:
"myobject": {
"type": "object",
"properties": {
"type": ["string", "array"]
}
}
Upvotes: 0
Views: 643
Reputation: 2147
If the keys are „free“ as you put it, you can use the additionalProperties
keyword like this:
{
"type": "object",
"additionalProperties": {
"type": ["string", "array"]
}
}
Upvotes: 1