Reference

Type-specific keywords

The type keyword is fundamental to JSON Schema. It specifies the data type for a schema.

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 may either be a string or an array:

  • If it's a string, it is the name of one of the basic types above.
  • If it is an array, it must be an array of strings, where each string is the name of one of the basic types, and each element is unique. In this case, the JSON snippet is valid if it matches any of the given types.

Here is a simple example of using the type keyword:

Copy icon
 logo-white schema
{ "type": "number" }
Copy icon
data
42
Checkmark iconcompliant to schema
Copy icon
data
42.0
Checkmark iconcompliant to schema
Copy icon
data
"42"
Error iconnot compliant to schema

In the following example, we accept strings and numbers, but not structured data types:

Copy icon
 logo-white schema
{ "type": ["number", "string"] }
Copy icon
data
42
Checkmark iconcompliant to schema
Copy icon
data
"Life, the universe, and everything"
Checkmark iconcompliant to schema
Copy icon
data
["Life", "the universe", "and everything"]
Error iconnot compliant to schema

For each of these types, there are keywords that only apply to those types. For example, numeric types have a way of specifying a numeric range, that would not be applicable to other types. In this reference, these validation keywords are described along with each of their corresponding types in the following chapters.

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!.