Through a json schema validator (like z-schema
), I would like to validate an integer formatted in a string, e.g.:
{
"myvalue": "45"
}
Currently, the following validation schema is:
{
"type": "string",
"pattern": "^[0-9]+$"
}
However, now it would be great to be able to validate a minimum and maximum value, like:
{
"type": "integer",
"minimum": 0,
"maximum": 32
}
However the above json value "45" is not an integer.
Without changing the
type
tointeger
, the best you can do is use thepattern
keyword to enforce the range using a regular expression. Here is an example of a regular expression to match integers from 0..32.