Reference

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
Objective-C
Swift
In Python, "integer" is analogous to the int type.
Copy icon
 logo-white schema
{ "type": "integer" }
Copy icon
data
42
Checkmark iconcompliant to schema
Copy icon
data
-1
Checkmark iconcompliant to schema

Numbers with a zero fractional part are considered integers:

Copy icon
data
1.0
Checkmark iconcompliant to schema

Floating point numbers are rejected:

Copy icon
data
3.1415926
Error iconnot compliant to schema

Numbers as strings are rejected:

Copy icon
data
"42"
Error iconnot compliant to schema

number

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

Language-specific info:
Python
Ruby
Objective-C
Swift
In Python, "number" is analogous to the float type.
Copy icon
 logo-white schema
{ "type": "number" }
Copy icon
data
42
Checkmark iconcompliant to schema
Copy icon
data
-1
Checkmark iconcompliant to schema

Simple floating point number:

Copy icon
data
5.0
Checkmark iconcompliant to schema

Exponential notation also works:

Copy icon
data
2.99792458e8
Checkmark iconcompliant to schema

Numbers as strings are rejected:

Copy icon
data
"42"
Error iconnot 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.

Copy icon
 logo-white schema
{ "type": "number", "multipleOf" : 10}
Copy icon
data
0
Checkmark iconcompliant to schema
Copy icon
data
10
Checkmark iconcompliant to schema
Copy icon
data
20
Checkmark iconcompliant to schema
Copy icon
data
23
Error iconnot compliant to schema

The multiple can be a floating point number:

Copy icon
 logo-white schema
{ "type": "number", "multipleOf" : 0.01}
Copy icon
data
4.02
Checkmark iconcompliant to schema
Copy icon
data
4.021
Error iconnot 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.

Copy icon
 logo-white schema
{ "type": "number", "minimum": 0, "exclusiveMaximum": 100}

Less than minimum:

Copy icon
data
-1
Error iconnot compliant to schema

minimum is inclusive, so 0 is valid:

Copy icon
data
0
Checkmark iconcompliant to schema
Copy icon
data
10
Checkmark iconcompliant to schema
Copy icon
data
99
Checkmark iconcompliant to schema

exclusiveMaximum is exclusive, so 100 is not valid:

Copy icon
data
100
Error iconnot compliant to schema

Greater than maximum:

Copy icon
data
101
Error iconnot 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:

Copy icon
 logo-white schema
{ "type": "number", "minimum": 0, "maximum": 100, "exclusiveMaximum": true}

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

Copy icon
data
0
Checkmark iconcompliant to schema
Copy icon
data
10
Checkmark iconcompliant to schema
Copy icon
data
99
Checkmark iconcompliant to schema

exclusiveMaximum is true, so 100 is not included:

Copy icon
data
100
Error iconnot compliant to schema

Greater than maximum:

Copy icon
data
101
Error iconnot compliant to schema

Need Help?

Did you find these docs helpful?

Help us make our docs great!

At JSON Schema, we value docs contributions as much as every other type of contribution!

Still Need Help?

Learning JSON Schema is often confusing, but don't worry, we are here to help!.