Reputation: 21
I was trying to come up with a schema to validate JSON objects like the following:
{
"id":"some_id",
"properties":{
"A":{
"name":"a",
"isindex":true
},
"B":{
"name":"b"
},
"C":{
"name":"c"
}
}
}
The deal is:
.
{
"id":"some_id",
"properties":{
"A":{
"type":"string",
"isindex":true
},
"B":{
"type":"string"
},
"C":{
"type":"array",
"isindex":true
}
}
}
Actually, I am not sure if the JSON schema is the right tool for for this.
Any or all help is appreciated!
Upvotes: 0
Views: 1340
Reputation: 24489
JSON Schema is the right tool for this kind of thing, but you have stumbled on a specific case that it doesn't handle. You can assert that at least one matches a particular schema, but you can't assert that one and only one matches.
The best thing you can do is change your data structure to something like this ...
{
"id":"some_id",
"properties":{
"A":{
"name":"a"
},
"B":{
"name":"b"
},
"C":{
"name":"c"
}
},
"index": "A"
}
Upvotes: 2