Numeric Types
The number type and its family of integer, unsigned, and float shortcuts.
The number type validates a numeric value. It is the base of a small family of predefined shortcuts — int, uint, int8, byte, and so on — where each shortcut is simply number with a fixed set of constraints baked in. For example, int8 is number restricted to whole values in −128…127.
Two related numeric types have their own pages: BigInt (arbitrary-precision integers, suffix
n) and Decimal (fixed-precision decimals, suffixm). For how numbers are written (decimal, hex, octal, binary, scientific,NaN,Inf), see Numeric Values.
The number family
Each name below is the base number type plus preset constraints. A conformant validator MUST recognize all of these names.
number
no
IEEE-754 double
float
no
IEEE-754 double
int
yes
unbounded integer
uint
yes
integer ≥ 0
int8
yes
−128 … 127
uint8 / byte
yes
0 … 255
int16
yes
−32 768 … 32 767
uint16
yes
0 … 65 535
int32
yes
−2 147 483 648 … 2 147 483 647
uint32
yes
0 … 4 294 967 295
byte is an alias for uint8. A value outside a type's range MUST be rejected with an invalid-range error:
age: int8
---
~ 200 # ✗ invalid-range — int8 max is 127Whole-number rule. The
int/uint/int8…32/uint8…32shortcuts MUST reject values with a fractional part (intaccepts42, not42.5).numberandfloataccept any finite double.
Reserved (not yet supported).
int64,uint64,float32, andfloat64are reserved for future use; the reference implementation currently rejects them.
TypeDef
A number MemberDef accepts only the options below. Any other key is invalid.
type
string
Type name (number or any family member). First positional value.
default
number
Value used when the member is omitted. Second positional value.
choices
array of number
Restricts the value to a fixed set. Third positional value.
min
number
Minimum allowed value (inclusive).
max
number
Maximum allowed value (inclusive).
multipleOf
number
The value must be an exact multiple of this.
format
string
Serialization format: decimal (default), hex, octal, binary, scientific.
optional
bool
If true, the member may be omitted. Shorthand: ? suffix on the key.
null
bool
If true, the member may be null. Shorthand: * suffix on the key.
Constraints
min / max
Inclusive bounds. A value outside the bounds is rejected with invalid-range.
An explicit
min/maxreplaces a shortcut's built-in bound rather than narrowing it — e.g.{ int8, min: -200 }currently accepts −200. See Implementation status below.
multipleOf
The value must be an exact multiple of the given number.
choices
Restricts the value to a fixed set. As the third positional value it may omit the key.
format
Controls how the number is written on serialization; it does not restrict which input notations are accepted (any notation is read).
Special values
NaN and Inf/-Inf are valid only for number/float. When combined with a numeric bound, the reference implementation currently coerces them to null rather than validating them — see Implementation status.
Optional, nullable & defaults
How a member resolves (verified behavior):
value present, valid
the value
value present, out of range
invalid-range error
value is N (null), key is nullable (*)
null
value is N (null), key is not nullable
null-not-allowed error
value omitted, default set
the default
value omitted, key optional (?), no default
absent
value omitted, required, no default
value-required error
Use the
*suffix for nullability. The keyednull: Toption is part of the TypeDef but is not currently honored — only the*suffix enables null. (See below.)
Implementation status (beta)
A few behaviors on this page describe the agreed target; the reference implementation is catching up:
Whole-number enforcement for the
intfamily is not yet applied (intcurrently accepts3.14).bytealias is being added (currently onlyuint8is recognized).Explicit
min/maxcan widen a shortcut's range (under review).NaN/Infunder a bound resolve tonull(under review).Keyed
null:is not honored; use the*suffix.
Examples
A schema mixing notations and family members (adapted from the playground):
Any input notation works for any number type — 0x11, 0o21, 0b10001, and 17 all denote the same value.
See Also
Numeric Values — how numbers are written
Last updated
Was this helpful?
