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
Base Dialect 2020-12
Changed In Draft 6 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 the following. Note that while the ECMA 404 JSON standard defines the JSON grammar without mention of encodings, the IETF RFC 8259 JSON standard provides specific guidance for JSON numbers and JSON strings which are documented in the Interoperable Encoding column. Other encodings will likely not be accepted by JSON parsers.

Type Description Interoperable Encoding
"null" The JSON null constant N/A
"boolean" The JSON true or false constants N/A
"object" A JSON object N/A
"array" A JSON array N/A
"number" A JSON number IEEE 764 64-bit double-precision floating point encoding (except NaN, Infinity, and +0)
"integer" A JSON number that represents an integer 64-bit signed integer encoding (from -(2^53)+1 to (2^53)-1)
"string" A JSON string UTF-8 Unicode encoding

Note that while the JSON grammar does not distinguish between integer and real numbers, JSON Schema provides the integer logical type that matches either integers (such as 2), or real numbers where the fractional part is zero (such as 2.0). Additionally, numeric constructs inherent to floating point encodings (like NaN and Infinity) are not permitted in JSON. However, the negative zero (-0) is permitted.

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
Valid A number in scientific expontential notation is valid Instance
1.0e+28
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 ]
A schema that describes integer instances Schema
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "integer"
}
Valid An integer is valid Instance
42
Valid A real number with a zero fractional part is valid Instance
3.0
Invalid A real number with a non-zero fractional part is invalid Instance
3.14