Skip to main content
The type keyword validates that an instance matches one or more specified data types.

Syntax

The value of type must be either:
  • A string representing a single type
  • An array of strings representing multiple allowed types
If an array is used, it must be non-empty with unique elements.

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

Valid instances:
Invalid instances:

Integer Type

Valid instances:
Invalid instances:

Multiple Types

Valid instances:
Invalid instances:

Nullable String

Valid instances:
Invalid instances:

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 value 3.0 is considered valid because it has a zero fractional part
  • The array form of type is useful for creating nullable types or allowing multiple data types