Reference

JSON data types

The type keyword is fundamental to JSON Schema because it specifies the data type that a schema should expect.

At its core, JSON Schema defines the following basic types:

These types have analogs in most programming languages, though they may go by different names.

Language-specific info:
Python
Ruby
Perl
Objective-C
Swift

The following table maps from the names of JSON types to their analogous types in Python:

JSONPython
stringstring [1]
numberint/float [2]
objectdict
arraylist
booleanbool
nullNone

Footnotes

[1] Since JSON strings always support unicode, they are analogous to unicode on Python 2.x and str on Python 3.x.

[2] JSON does not have separate types for integer and floating-point.

The type keyword can take two forms:

  1. A single string. When it is a single string, it must be one of the types mentioned above (array, boolean, integer, number, null, object, regular expressions, or string). This specifies that the instance data is only valid when it matches that specific type.

Here is an example of using the string keyword as a single string:

schema
{ "type": "number" }
data
42
compliant to schema
data
42.0
compliant to schema
data
"42"
not compliant to schema
  1. An array of strings. When type is used as an array, it contains more than one string specifying the types mentioned above. In this case, the instance data is valid if it matches any of the given types.

Here is an example using the type keyword as an array of strings, where instance data of the type string and number are valid but array isn't:

schema
{ "type": ["number", "string"] }
data
42
compliant to schema
data
"Life, the universe, and everything"
compliant to schema
data
["Life", "the universe", "and everything"]
not compliant to schema

JSON Schema offers a variety of keywords to validate data against specific types. The following table outlines keywords that are specifically designed for each basic data type:

Type KeywordSpecific KeywordsDescription
arrayitems, additionalItems, minItems, maxItems, uniqueItemsDefine item schemas, additional item handling, item count constraints, and uniqueness.
numberminimum, maximum, exclusiveMinimum, exclusiveMaximum, multipleOfDefine numeric ranges, including exclusive bounds and divisibility.
objectrequired, properties, additionalProperties, patternProperties, minProperties, maxProperties, dependenciesDefine required properties, property schemas, additional property handling, pattern-based property matching, and property count constraints.
stringminLength, maxLength, pattern, formatRestrict string length, pattern matching, and format validation (e.g., email, date).

Understanding these basic data types gives you a strong foundation for building more complex JSON Schemas.

Dive deeper into our reference and explore JSON Schema's flexibility for creating complex data structures:

By utilizing these advanced features, you can create robust and flexible JSON Schemas that meet your exact needs.

Need Help?

Did you find these docs helpful?

Help us make our docs great!

At JSON Schema, we value docs contributions as much as every other type of contribution!

Still Need Help?

Learning JSON Schema is often confusing, but don't worry, we are here to help!.