Types

JSON supports very limited number of types: string, number, boolean, object, array, null. Specifying JSON type is often not enough when it comes HTTP API definition and to what is allowed/prohibited as query/header/body value. For example, if the endpoint expects date and time in ISO 8601 format then in JSON it's just a string, though API user supposed to pass a string only in a specific format.

The null is a problem across all JSON types. All fields can be null in JSON. Though usually API is very sensitive to null values and does not allow nulls everywhere.

Spec has it's own list of supported types to close gaps mentioned above and to provide declarative way of defining types. This section describes these types.

Primitive Types

Nullable Types

By default all types can't have null value. The ? modifier after type defines nullable type. For example string can not be null though string? can have null value.

Array and Dictionary

Following modifiers allow to specify data structures:

For example string[] represents array of strings. The type int{} represents JSON object where all properties values are integers.

Last updated