multipleOf : Number

multipleOf

Number

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

Kind Assertion
Applies To Number
Dialect 2020-12
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
Also see

The multipleOf keyword is used to specify that an instance must be a multiple of a given number. The value of this keyword must be strictly greater than zero.

  • Applicable only to number and integer type.
  • Validates if an instance is divisible by the specified number.
  • Setting multipleOf to 0 is not valid.

Examples

Schema with 'multipleOf' set to an integer Schema
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "multipleOf": 5
}
A numeric instance that is a multiple of 5 is valid Instance
10
A numeric instance that is not a multiple of 5 is invalid. Instance
8
-15 is a multiple of 5 Instance
-15
An instance with a string value is valid Instance
"foo"
  • multipleOf only affects numeric instances and has no effect on other types of instances.
Schema with 'multipleOf' set to a real number Schema
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "number",
  "multipleOf": 4.1
}
A numeric instance that is a multiple of 4.1 is valid Instance
8.2
2 is not a multiple of 4.1 Instance
2
0 is a multiple of 4.1 Instance
0
An instance with a string value is invalid Instance
"foo"
  • multipleOf only affects numeric instances and has no effect on other types of instances. However, the above instance failed due to the type constraint.