Edit online

JSON Schema Component Properties

Table 1. JSON Schema Diagram Component Properties
Properties Group Property Name Description
Common Properties type

Specifies the type of data that the schema is expecting to validate. This keyword is not mandatory and the value must be a string representing a valid data type, or an array of strings representing a valid list of data types.

When specifying multiple types, their order is irrelevant to the validation process, but make sure that a data type is specified only once.

$ref An instance is valid against this keyword if it is valid against the schema that points to the location indicated in its value. The value must be a string representing a URI, URI reference, URI template, or JSON pointer.
Note: A schema version 2019-09 or 2020-12 that contains a $ref in conjunction with other type-specific keywords (such as properties or items) is processed as a combined schema, under the allOf criterion. This means that for an instance to be valid, it has to validate against both the referenced schema and the schema defined in-place by those keywords.
$id Specifies a unique ID for a document or a document sub-schema. The value must be a string representing a URI. All sub-schema IDs are resolved relative to the document ID. It is not a required keyword, but it is considered best practice to use it.
enum An instance validates against this keyword if its value can be found in the items defined by its value. The value must be an array that contains anything (an empty array is not allowed).
const An instance validates against this keyword if its value equals the value of this keyword. The value can be anything.
$comment Contains an observation about the schema. The value must be a string.
readOnly Used to mark specific properties as read-only.
writeOnly Used to mark specific properties as write-only.
deprecated Used to indicate that the instance value is deprecated and should not be used since it might be removed in the future.
Object Properties additionalProperties

An object is valid against this keyword if all unchecked properties are valid against the schema defined by its value. Unchecked properties are the properties not checked by the properties and patternProperties keywords (if a property name is not present in the properties keyword and does not match any regular expression defined by the patternProperties keyword, then it is considered unchecked). The value must be a valid JSON schema (object or boolean).

To be more concise, if we have unchecked properties:

  • If the value of this keyword is true, it is always valid.

  • If the value is false, it is never valid.

  • If the value contains an object (schema), every property must be valid against that schema.

unevaluatedProperties Similar to the additionalProperties keyword except that this one can recognize properties that declared in subschemas.
maxProperties An object is valid against this keyword if the number of properties it contains is lower than or equal to its value. The value must be a non-negative integer. Using 0 as a value means that the object must be empty (no properties).
minProperties An object is valid against this keyword if the number of properties it contains is greater than or equal to its value. The value of this keyword must be a non-negative integer. Using 0 as a value has no effect.
patternProperties An object is valid against this keyword if every property where a property name (key) matches a regular expression from its value and is also valid against the corresponding schema. The value must be an object where the keys must be valid regular expressions and the corresponding values must be valid JSON schemas (object or boolean).
propertyNames An object is valid against this keyword if every property name (key) is valid against its value. The value must be a valid JSON schema (an object or a boolean).
required An object is valid against this keyword if it contains all property names (keys) specified by its value. The value must be a non-empty array of strings that represent property names.
dependencies An object is valid against this keyword if it meets all dependencies specified by its value.
Note: For 2019-09 and 2020-12 schemas, you should use the dependentRequired and dependentSchemas keywords instead.
dependentRequired An object is valid against this keyword if it meets all dependencies specified by its value. The value must be an object where property values must be arrays of strings representing property names, and the object must contain all property names.
dependentSchemas An object is valid against this keyword if it meets all dependencies specified by its value. The value must be an object where property values must be objects representing valid JSON schemas, and the whole object must match the entire schema.
Array Properties additionalItems An array is valid against this keyword if all unchecked items are valid against the schema defined by its value.
unevaluatedItems An array is valid against this keyword if the value is a valid JSON schema that will be applied to all array items that were not evaluated by other keywords for items (prefixItems, items, contains).
contains An array is valid against this keyword if at least one item is valid against the schema defined by its value. The value must be a valid JSON schema (object or boolean).
maxContains An array is valid against this keyword if the number of contains is lower than or equal to its value. The value must be a non-negative integer.
minContains An array is valid against this keyword if the number of contains is greater than or equal to its value. The value must be a non-negative integer.
items

An array is valid against this keyword if the items are valid against the corresponding schemas provided by its value. The value of this keyword can be:

  • A valid JSON schema (object or boolean). Every item must be valid against this schema.

  • An array of valid JSON schemas. Each item must be valid against the schema defined at the same position (index). Items that do not have a corresponding position (e.g. an array contains 5 items but this keyword only has 3) will be considered valid unless the additionalItems keyword is present, which will decide the validity.

maxItems An array is valid against this keyword if the number of items it contains is lower than or equal to its value. The value must be a non-negative integer.
minItems An array is valid against this keyword if the number of items it contains is greater than or equal to its value. The value must be a non-negative integer.
prefixItems An array is valid against this keyword if each item is a schema that corresponds to each index of the document’s array (where the first element validates the first element of the input array, the second element validates the second element of the input array, and so on).
uniqueItems An array is valid against this keyword if an item cannot be found more than once in the array. The value must be boolean. If set to false, the keyword validation will be ignored.
Number/Integer Properties exclusiveMaximum A number is valid against this keyword if it is strictly lower than its value. The value must be a number (integer or float) or boolean.
exclusiveMinimum A number is valid against this keyword if it is strictly greater than its value. The value must be a number (integer or float) or boolean.
maximum A number is valid against this keyword if it is lower than or equal to its value. The value must be a number (integer or float).
minimum A number is valid against this keyword if it is greater than or equal to its value. The value must be a number (integer or float).
multipleOf A number is valid against this keyword if the division between the number and its value results in an integer. The value must be a strictly positive number (zero is not allowed).
String Properties contentEncoding A string is valid against this keyword if it is encoded using the method indicated by its value. The value must be a string.
contentMediaType A string is valid against this keyword if its content has the media type (MIME type) indicated by its value. If the contentEncoding keyword is also specified, the decoded content must have the indicated media type. The value must be a string.
format Performs a semantic validation on data. The value must be a string that represents a format. The keyword behavior depends on the data type, meaning that the same format name for a string behaves differently on a number, or is missing, because not all data types must implement a format and usually differing data types have different formats.
maxLength A string is valid against this keyword if its length is lower than or equal to its value. The value must be a non-negative integer.
minLength A string is valid against this keyword if its length is greater than or equal to its value. The value must be a non-negative integer.
pattern A string is valid against this keyword if it matches the regular expression specified by its value. The value must be a string that represents a valid regular expression.