Number type

The number type is used for validating integer and float values.

{
  "type": "number"
}

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.

  1. minimum
  2. exclusiveMinimum
  3. maximum
  4. exclusiveMaximum
  5. multipleOf

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
}

11 - valid (greater)

10.5 - valid (equal)

10 - invalid (lower)

10.49 - invalid (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. If this keyword holds a boolean, then the minimum keyword is required and is used as reference for comparison.

{
  "type": "number",
  "exclusiveMinimum": 10.5
}

11 - valid (greater)

10.6 - valid (greater)

10.5 - invalid (equal)

10 - invalid (lower)

{
  "type": "number",
  "minimum": 10.5,
  "exclusiveMinimum": true
}

11 - valid (greater)

10.6 - valid (greater)

10.5 - invalid (equal)

10 - invalid (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
}

10 - valid (lower)

10.5 - valid (equal)

10.6 - invalid (greater)

11 - invalid (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. If this keyword holds a boolean, then the maximum keyword is required and is used as reference for comparison.

{
  "type": "number",
  "exclusiveMaximum": 10.5
}

10 - valid (lower)

10.49 - valid (lower)

10.5 - invalid (equal)

11 - invalid (greater)

{
  "type": "number",
  "maximum": 10.5,
  "exclusiveMaximum": true
}

10 - valid (lower)

10.49 - valid (lower)

10.5 - invalid (equal)

11 - invalid (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
}

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)