type : String | Array<String>

type

String | Array<String>

Validation succeeds if the type of the instance matches the type represented by the given type, or matches at least one of the given types.

Value This keyword must be set to either a string that corresponds to one of the supported types, or a non-empty array of unique strings that correspond to one of the supported types
Kind Assertion
Applies To Any
Dialect 2020-12
Changed In Draft 4
Introduced In Draft 1
Vocabulary Validation
Specification https://json-schema.org/draft/2020-12/json-schema-validation.html#section-6.1.1
Metaschema https://json-schema.org/draft/2020-12/meta/validation
Official Tests draft2020-12/type.json
Default [ "null", "boolean", "object", "array", "number", "string" ]
Annotation None
Affected By None
Affects None

The supported types are as follows:

Type Description
"null" The JSON null constant
"boolean" The JSON true or false constants
"object" A JSON object
"array" A JSON array
"number" A JSON number
"integer" A JSON number that represents an integer
"string" A JSON string

Note that the JSON grammar does not distinguish between integer and real numbers. Still, JSON Schema provides the integer logical type.

Examples

A schema that describes numeric instances Schema
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "number"
}
Valid An integer is valid Instance
42
Valid A real number is valid Instance
3.14
Invalid A string is not valid Instance
"foo"
A schema that describes boolean or array instances Schema
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": [ "boolean", "array" ]
}
Valid The true boolean is valid Instance
true
Invalid A number is invalid Instance
1234
Valid An arbitrary array is valid Instance
[ 1, 2, 3 ]