multipleOf : Number

multipleOf

Number

A numeric instance is valid only if division by this keyword’s value results in an integer.

Value This keyword must be set to a number that is greater than zero
Kind Assertion
Applies To Number
Base Dialect 2020-12
Changed In None
Introduced In Draft 4
Vocabulary Validation
Specification https://json-schema.org/draft/2020-12/json-schema-validation.html#section-6.2.1
Metaschema https://json-schema.org/draft/2020-12/meta/validation
Official Tests draft2020-12/multipleOf.json
Default 1
Annotation None
Affected By None
Affects None
Also See

The multipleOf keyword restricts number instances to be multiples of the given number. Note that the number 0 is a multiple of every number, as for every number k, the mutiplication 0 * k yield an integer value (in this case always 0). This case is not to be confused with division by zero, which is not a permitted operation in most computer systems.

Remember that JSON Schema is a constraint-driven language. Therefore, non-number instances successfully validate against this keyword. If needed, make use of the type keyword to constraint the accepted type accordingly.

Examples

A schema that constrains number instances to be multiples of the integer 5 Schema
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "multipleOf": 5
}
Valid An integer value that is a positive multiple of 5 is valid Instance
10
Valid An integer value that is a negative multiple of 5 is valid Instance
-5
Valid The real number representation of an integer value that is a positive multiple of 5 is valid Instance
15.0
Invalid An integer value that is not a multiple of 5 is invalid Instance
8
Valid The zero integer value is a multiple of every number Instance
0
Valid A non-number value is valid Instance
"100000"
A schema that constrains number instances to be multiples of the real number 2.3 Schema
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "multipleOf": 2.3
}
Valid A number value that is a positive multiple of 2.3 is valid Instance
6.9
Valid A number value that is a negative multiple of 2.3 is valid Instance
-4.6
Invalid A number value that is not a multiple of 2.3 is invalid Instance
2.4
Valid The zero integer value is a multiple of every number Instance
0
Valid A non-number value is valid Instance
"100000"
A schema that constrains number instances to have up to 2 digits in the fractional part Schema
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "multipleOf": 0.01
}
Valid Any integer value is valid Instance
2
Valid A number value with 1 digit in the fractional part is valid Instance
5.1
Valid A number value with 2 digits in the fractional part is valid Instance
-12.34
Invalid A number value with 3 digits in the fractional part is invalid Instance
1.234
Valid The zero integer value is a multiple of every number Instance
0
Valid A non-number value is valid Instance
"100000"