Numeric types

There are two numeric types in JSON Schema: integer and number. They share the same validation keywords.

JSON has no standard way to represent complex numbers, so there is no way to test for them in JSON Schema.

integer

The integer type is used for integral numbers. JSON does not have distinct types for integers and floating-point values. Therefore, the presence or absence of a decimal point is not enough to distinguish between integers and non-integers. For example, 1 and 1.0 are two ways to represent the same value in JSON. JSON Schema considers that value an integer no matter which representation was used.

Language-specific info:
Python
Ruby
In Python, "integer" is analogous to the int type.
schema
1
{ "type": "integer" }
data
1
42
compliant to schema
data
1
-1
compliant to schema

Numbers with a zero fractional part are considered integers:

data
1
1.0
compliant to schema

Floating point numbers are rejected:

data
1
3.1415926
not compliant to schema

Numbers as strings are rejected:

data
1
"42"
not compliant to schema

number

The number type is used for any numeric type, either integers or floating point numbers.

Language-specific info:
Python
Ruby
In Python, "number" is analogous to the float type.
schema
1
{ "type": "number" }
data
1
42
compliant to schema
data
1
-1
compliant to schema

Simple floating point number:

data
1
5.0
compliant to schema

Exponential notation also works:

data
1
2.99792458e8
compliant to schema

Numbers as strings are rejected:

data
1
"42"
compliant to schema

Multiples

Numbers can be restricted to a multiple of a given number, using the multipleOf keyword. It may be set to any positive number.

schema
1
{
2
"type": "number",
3
"multipleOf" : 10
4
}
data
1
0
compliant to schema
data
1
10
compliant to schema
data
1
20
compliant to schema
data
1
23
not compliant to schema

The multiple can be a floating point number:

schema
1
{
2
"type": "number",
3
"multipleOf" : 0.01
4
}
data
1
4.02
compliant to schema
data
1
4.021
not compliant to schema

Range

Ranges of numbers are specified using a combination of the minimum and maximum keywords, (or exclusiveMinimum and exclusiveMaximum for expressing exclusive range).

If x is the value being validated, the following must hold true:

xminimum
x > exclusiveMinimum
xmaximum
x < exclusiveMaximum

While you can specify both of minimum and exclusiveMinimum or both of maximum and exclusiveMaximum, it doesn't really make sense to do so.

schema
1
{
2
"type": "number",
3
"minimum": 0,
4
"exclusiveMaximum": 100
5
}

Less than minimum:

data
1
-1
not compliant to schema

minimum is inclusive, so 0 is valid:

data
1
0
compliant to schema
data
1
10
compliant to schema
data
1
99
compliant to schema

exclusiveMaximum is exclusive, so 100 is not valid:

data
1
100
not compliant to schema

Greater than maximum:

data
1
101
not compliant to schema
Draft-specific info:
Draft 4

In JSON Schema Draft 4, exclusiveMinimum and exclusiveMaximum work differently. There they are boolean values, that indicate whether minimum and maximum are exclusive of the value. For example:

if exclusiveMinimum is false, xminimum
if exclusiveMinimum is true, x > minimum.

This was changed to have better keyword independence.

Here is an example using the older Draft 4 convention:

schema
1
{
2
"type": "number",
3
"minimum": 0,
4
"maximum": 100,
5
"exclusiveMaximum": true
6
}

Less than minimum: json // props { "indent": true, "valid": false } -1 exclusiveMinimum was not specified, so 0 is included:

data
1
0
compliant to schema
data
1
10
compliant to schema
data
1
99
compliant to schema

exclusiveMaximum is true, so 100 is not included:

data
1
100
not compliant to schema

Greater than maximum:

data
1
101
not compliant to schema