Sergei Basharov Sergei Basharov - 24 days ago 6
JSON Question

Can I set exact value in a JSON Schema?

I use JSON Schema to validate app objects against some schema for testing.

I see that I can set

minimum
and
maximum
values for a property:

"responseCode": {
"type": "integer",
"minimum": 100,
"maximum": 500
}


But I couldn't find if I can set an exact required value, like
"value":123
.

Is it possible to set it to exactly what I need to validate for?

esp esp
Answer

You can:

{ "enum": [123] }

There is a proposal to add the keyword constant in the next standard version:

{ "constant": 123 }

constant is supported by Ajv (a bit of self-promotion here).