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 |
---|---|
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.
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": "https://json-schema.org/draft/2020-12/schema",
"multipleOf": 5
}
10
-5
15.0
8
0
"100000"
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"multipleOf": 2.3
}
6.9
-4.6
2.4
0
"100000"
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"multipleOf": 0.01
}
2
5.1
-12.34
1.234
0
"100000"