multipleOf : Number
multipleOf
NumberA 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
Hint: Use the jsonschema metaschema and jsonschema lint commands to catch keywords set to invalid values
|
|---|---|
| Kind | Assertion |
| Applies To | Number |
| Base Dialect | Draft 4 |
| Changed In | None |
| Introduced In | Draft 4 |
| Vocabulary | Validation |
| Specification | https://json-schema.org/draft-04/draft-fge-json-schema-validation-00#rfc.section.5.1.1 |
| Metaschema | http://json-schema.org/draft-04/schema# |
| Official Tests | draft4/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
multiplication 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.
Digging Deeper
Setting this keyword to negative powers of 10, such as
0.01 (10^-2), 0.001 (10^-3), and 0.0001 (10^-4), is a common mechanism to
control the maximum number of digits in the fractional part of a real number.
For example, 1.2 and -12.34 are multiples of 0.01, but 1.234 is
not.
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
{
"$schema": "http://json-schema.org/draft-04/schema#",
"multipleOf": 5
}10-515.080"100000"{
"$schema": "http://json-schema.org/draft-04/schema#",
"multipleOf": 2.3
}6.9-4.62.40"100000"{
"$schema": "http://json-schema.org/draft-04/schema#",
"multipleOf": 0.01
}25.1-12.341.2340"100000"