type keyword validates that an instance matches one or more specified data types.
Syntax
The value oftype must be either:
- A string representing a single type
- An array of strings representing multiple allowed types
Allowed Types
The following type values are valid:"null"- JSON null value"boolean"- JSON boolean (true or false)"object"- JSON object"array"- JSON array"number"- JSON number (including integers and decimals)"string"- JSON string"integer"- A number with a zero fractional part
Validation Rules
Single type: An instance validates successfully if its type matches the specified type. Multiple types: An instance validates successfully if its type matches any of the types in the array.Examples
Single Type
Integer Type
Multiple Types
Nullable String
Notes
- The
"integer"type is not a primitive JSON type but is provided as a convenient way to validate whole numbers - When using
"integer", the value3.0is considered valid because it has a zero fractional part - The array form of
typeis useful for creating nullable types or allowing multiple data types