I have a special enum case in my code and need to validate against it:
{
"status": 10
}
Let's use this imaginary list of valid values:
var valid = [10, 20, 23, 27];
How can I alter my JSON Schema to validate one of these values?
{
type: 'object',
required: ['status'],
properties: {
status: { type: number },
}
}
You just define the status
property as an enum
:
{
"type" : "object",
"required" : ["status"],
"properties" : {
"status" : {
"type" : "number",
"enum" : [10, 20, 23, 27]
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With