Number type
Keywords for number type
The number
type is used for validating integer and float values.
{
"type": "number"
}
Input | Status |
---|---|
5 |
valid - integer |
-10.8 |
valid - float |
"123" |
invalid - is string |
null |
invalid - is null |
Validation keywords
The following keywords are supported by the number
type, and evaluated
in the presented order. All keywords are optional.
minimum
A number is valid against this keyword if is greater than, or equal to, the value of this keyword. Value of this keyword must be a number (integer or float).
{
"type": "number",
"minimum": 10.5
}
Input | Status |
---|---|
11 |
valid - is greater |
10.5 |
valid - is equal |
10 |
invalid - is lower |
10.49 |
invalid - is lower |
exclusiveMinimum
A number is valid against this keyword if is strictly greater than the value of this keyword. Value of this keyword must be a number (integer or float) or a boolean.
{
"type": "number",
"exclusiveMinimum": 10.5
}
Input | Status |
---|---|
11 |
valid - is greater |
10.6 |
valid - is greater |
10.5 |
invalid - is equal |
10 |
invalid - is lower |
If this keyword holds a boolean,
then the minimum
keyword is required and is used as reference for comparison.
This is not officially defined, you can disable it by setting allowExclusiveMinMaxAsBool
parser option to false
.
{
"type": "number",
"minimum": 10.5,
"exclusiveMinimum": true
}
Input | Status |
---|---|
11 |
valid - is greater |
10.6 |
valid - is greater |
10.5 |
invalid - is equal |
10 |
invalid - is lower |
maximum
A number is valid against this keyword if is lower than, or equal to, the value of this keyword. Value of this keyword must be a number (integer or float).
{
"type": "number",
"maximum": 10.5
}
Input | Status |
---|---|
10 |
valid - is lower |
10.5 |
valid - is equal |
10.6 |
invalid - is greater |
11 |
invalid - is greater |
exclusiveMaximum
A number is valid against this keyword if is strictly lower than the value of this keyword. Value of this keyword must be a number (integer or float) or a boolean.
{
"type": "number",
"exclusiveMaximum": 10.5
}
Input | Status |
---|---|
10 |
valid - is lower |
10.49 |
valid - is lower |
10.5 |
invalid - is equal |
11 |
invalid - is greater |
If this keyword holds a boolean,
then the maximum
keyword is required and is used as reference for comparison.
This is not officially defined, you can disable it by setting allowExclusiveMinMaxAsBool
parser option to false
.
{
"type": "number",
"maximum": 10.5,
"exclusiveMaximum": true
}
Input | Status |
---|---|
10 |
valid - is lower |
10.49 |
valid - is lower |
10.5 |
invalid - is equal |
11 |
invalid - is greater |
multipleOf
A number is valid against this keyword if the division between the number and the the value of this keyword results in an integer. Value of this keyword must be a strictly positive number (zero is not allowed).
{
"type": "number",
"multipleOf": 0.5
}
Input | Status |
---|---|
10 |
valid - 10 / 0.5 = 20 |
1.5 |
valid - 1.5 / 0.5 = 3 |
-2 |
valid - -2 / 0.5 = -4 |
10.2 |
invalid - 10.2 / 0.5 = 20.40 |
-3.6 |
invalid - -3.6 / 0.5 = -7.2 |