JSON Schema validation keywords with more explanation

JSON schema contains so many keywords, some applies on any Instance and some applies only on Numerics, Strings, Arrays and Objects. All this are separated into multiple types,

Any instance type keywords :

type :

Value of this keywords is String or Array, Here Array elements must be String and unique. Here values must be one of the following types,

  • "null"
  • "boolean"
  • "object"
  • "array"
  • "number"
  • "string"
  • "integer"

enum :

It contains array of elements with minimum length of 1 and with any value including null. Instance value must be equal to any one of the elements else JSON schema validation will be failed.

const :

Instance can be any type but instance value must be equal to value of the keyword.

Numeric instances keywords (number and integer) :

multipleOf :

This value need be a number and greater than 0. Instance value must be multiple of keyword's value.

maximum :

This value need be a number and represents upper limit of instance value. Instance value must be less than or equal to keyword's value.

exclusiveMaximum :

This value need be a number and represents upper limit of instance value. Instance value must be less than keyword's value.

minimum :


This value need be a number and represents upper limit of instance value. Instance value must be greater than or equal to keyword's value.

exclusiveMinimum :

This value need be a number and represents upper limit of instance value. Instance value must be greater than keyword's value.

Strings keywords :

maxLength :

This value need be a positive integer. String instance length is less than or equal to keyword's value.

minLength :

This value need be a positive integer. String instance length is greater than or equal to keyword's value. Default value is zero.

pattern :

This value need to be a string and valid regular expression. String instance should match the regular expression provided as keyword's value.

Array keywords :

items :

This value must be either a valid JSON Schema or an array of valid JSON Schemas. This keyword doesn't validate instance directly, it validate child instance arrays.

If items value is a schema then all elements in the array should follow the schema. If items value is an array of schemas, each array index of schema refers to same index array element. Default value is an empty schema.

additionalItems :

This value must be a valid JSON Schema. This keyword value used only if items value is array and if Array instance is length is greater than items array length then additional array instances are follows this keyword's schema.
This key words ignored when items is a JSON schema or default value.

maxItems :

This value need be a positive integer. Array instance length is less than or equal to keyword's value.

minItems :


This value need be a positive integer. Array instance length is greater than or equal to keyword's value.

uniqueItems :

This value must be a boolean. If boolean value is true then all of its array elements should be unique.

contains :

This value must be a valid JSON Schema. At least one of the array instance elements must be valid against the given schema in this keyword's value.

Objects keywords :

maxProperties :

This value need be a positive integer. Number of properties in object instance is less than or equal to keyword's value.

minProperties :

This value need be a positive integer. Number of properties in object instance is greater than or equal to keyword's value.

required :

This value must be an array. Array elements must be strings and must be unique. An object instance must have every item in the array is the name of a property in the instance.

properties :

This value must be an object and each value of this object must be a valid JSON Schema. JSON schema validates child instance with same key/property name in keyword's key/property name.

additionalProperties :

This value must be an object. Keys/Properties missing in "properties" keyword are validated with "additionalProperties" JSON schema.

patternProperties :

This value must be an object. Child instances validate for objects, and does not directly validate the immediate instance itself and also validations primitive instance type against this keyword. For each instance name that matches any regular expressions that appear as a property name in this keyword's value.

dependencies :

This keyword specifies rules that are evaluated if the instance is an object and contains a certain property. This keyword's value must be an object. Each property specifies a dependency. Each dependency value MUST be an array or a valid JSON Schema.

If the dependency value is a subschema, and the dependency key is a property in the instance, the entire instance must validate against the dependency value.

If the dependency value is an array, each element in the array, if any, must be a string, and must be unique. If the dependency key is a property in the instance, each of the items in the dependency value must be a property that exists in the instance.

propertyNames :

This value must be a valid JSON Schema. If the instance is an object, this keyword validates if every property name in the instance validates against the provided schema. Note the property name that the schema is testing will always be a string.

Comments

Popular posts from this blog

conditional subschemas (writing conditions inside a JSON Schema)

nodejs/javascript client for Rabbitmq