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 not equal to zero
Kind Assertion
Applies To Number
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 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.

  • Validates if an instance is divisible by the specified number.

Examples

Schema with 'multipleOf' set to an integer Schema
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "multipleOf": 5
}
Valid A numeric instance that is a multiple of 5 is valid Instance
10
Invalid A numeric instance that is not a multiple of 5 is invalid. Instance
8
Valid -15 is a multiple of 5 Instance
-15
Valid 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
}
Valid A numeric instance that is a multiple of 4.1 is valid Instance
8.2
Invalid 2 is not a multiple of 4.1 Instance
2
Valid 0 is a multiple of 4.1 Instance
0
Invalid 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.