Edit online

JSON Schema Components

Schema

Figure 1. The schema Component

Description: Defines the root element of a JSON schema. A JSON schema document contains all the steps that are necessary to be performed to validate JSON documents and it contains a collection of JSON schema components.

Property

Figure 2. Example of a property Component

Description: Each key:value pair is known as a property of the object. The value can be any JSON data type.

Properties

Figure 3. The properties Component
Description: An object is valid against the properties keyword if every property that is present in both the object and the value of this keyword validates against the corresponding schema. The value must be an object, where properties must contain valid JSON schemas (object or boolean). Only the property names that are present in both the object and the keyword value are checked.
Note: Properties with a boolean value are presented in diagram as components. You can change the boolean value by modifying the any type property value. You can also convert a boolean any type property into a standard type property using the Convert property to standard type contextual menu action.

Pattern Property

Figure 4. Example of a patternProperty Component

Description: Maps regular expressions to schemas. If a property name matches the given regular expression, the property value must validate against the corresponding schema.

Pattern Properties

Figure 5. The patternProperties Component

Description: An object is valid against the patternProperties keyword if every property where a property name (key) matches a regular expression from the value of this keyword 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).

Unevaluated Properties (for 2019-09 or 2020-12 schemas)

Figure 6. The unevaluatedProperties Component

Description: An object is valid against the unevaluatedProperties keyword if every unevaluated property is valid against the schema defined by the value of this keyword. Unevaluated properties are the properties that were not evaluated anywhere in the current schema. This keyword can see through adjacent keywords, such as allOf.

Definition

Figure 7. Example of a definition Component

Description: The definition of a component of a schema. It can be referenced from a property to define its specification.

Definitions

Figure 8. The definitions Component

or

Description: The optional definitions keyword (or $defs for draft 2019-09 or 2020-12 schemas) does not directly validate data, but it contains a map of validation schemas. The value can be anything.
Note: Definitions with a boolean value are presented in diagram as components. You can change the boolean value by modifying the definition's any type property value. You can also convert a definition's boolean any type property into a standard type property using the Convert definition to standard type contextual menu action.

Additional Properties

Figure 9. The additionalProperties Component

Description:

An object is valid against the additionalProperties keyword if all unchecked properties are valid against the schema defined by the value of this keyword. 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 there are unchecked properties:
  • If the value of the additionalProperties 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.

Additional Items

Figure 10. The additionalItems Component

Description: An array is valid against the additionalItems keyword if all unchecked items are valid against the schema defined by the keyword value. An item is considered unchecked if the items keyword or prefixItems keyword (starting with 2020-12) contains an array of schemas and does not have a corresponding position (index). The value must be a valid JSON schema (object or boolean).

Items

Figure 11. The items Component
Description: An array is valid against the items keyword if the items are valid against the corresponding schemas provided by the keyword value. The value 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) are considered valid unless the additionalItems keyword is present, which will decide the validity.

Prefix Items (for 2020-12 schemas)

Figure 12. The prefixItems Component

Description: An array is valid against the prefixItems keyword if items are valid against the corresponding schemas provided by the keyword value. The value of this keyword must be an array of valid JSON schemas and each item must be valid against the schema defined at the same position (index). Items that do not have a corresponding position (an array contains 5 items and this keyword only has 3) will be considered valid, unless the items keyword is present (which will decide the validity).

Unevaluated Items (for 2019-09 or 2020-12 schemas)

Figure 13. The unevaluatedItems Component

Description: An object is valid against the unevaluatedItems keyword if every unevaluated item is valid against the schema defined by the value of this keyword. Unevaluated items are the items that were not evaluated anywhere in the current schema. This keyword can see through adjacent keywords, such as allOf.

AllOf

Figure 14. Example of an allOf Component

Description: An instance is valid against the allOf keyword if it is valid against all schemas defined by the value of this keyword. The value of this keyword must be an array of valid JSON schemas (objects or boolean).

AnyOf

Figure 15. Example of an anyOf Component

Description: An instance is valid against the anyOf keyword if it is valid against at least one schema defined by the value of this keyword. The value must be an array of valid JSON schemas (objects or boolean).

OneOf

Figure 16. Example of an oneOf Component

Description: An instance is valid against the oneOf keyword if it is valid against exactly one schema defined by the value of this keyword. The value must be an array of valid JSON schemas (object or boolean).

Not

Figure 17. Example of a not Component

Description: An instance is valid against the not keyword if it is not valid against the schema defined by the value of this keyword. The value must be a valid JSON schema (object or boolean).

If/Then/Else

Figure 18. Examples of an if, then, and else Components
Description: A conditional structure that contains three keywords: if, then, and else. Every keyword value must be a valid JSON schema (object or boolean). When the if keyword is not present, the then and else keywords are ignored. When the if keyword is present, at least one of the then or else keywords should also be present (or both). The instance is valid against this keyword in one of the following cases:
  • The if keyword validates the instance and the then keyword also validates it.
  • The if keyword does not validate the instance but the else keyword validates it.

Dependencies

Figure 19. The dependencies Component

Description: An object is valid against the dependencies keyword if it meets all dependencies specified by this keyword value. Only property names (from this keyword value) that are also present in the object are checked. The value of this keyword must be an object, where property values can be:

  • Objects representing valid JSON schemas and the whole object must match the entire schema.
    Important: For draft 2019-09 and 2020-12 schemas, you should use the dependentSchemas keyword instead.
  • Arrays of strings representing property names, then the object must contain all property names.
    Important: For draft 2019-09 and 2020-12 schemas, you should use the dependentRequired keyword instead.

Dependent Required (for 2019-09 or 2020-12 schemas)

Figure 20. The dependentRequired Component

Description: An object is valid against the dependentRequired keyword if it meets all dependencies specified by this keyword value. The value of this keyword must be an object where property values must be arrays of strings representing property names, and the object must contain all property names. Only property names (from this keyword value) that are also present in the object are checked.

Dependent Schemas (for 2019-09 or 2020-12 schemas)

Figure 21. The dependentSchemas Component

Description: An object is valid against the dependentSchemas keyword if it meets all dependencies specified by this keyword value. The value of this keyword must be an object where property values must be objects representing valid JSON schemas, and the whole object must match the entire schema. Only property names (from this keyword value) that are also present in the object are checked.