JSON Schema Validation Keywords

Q

How many validation keywords are supported in JSON Schema?

✍: FYIcenter.com

A

The current JSON Schema specification supports 29 validation keywords:

  • "multipleOf" - If the JSON instance is a number, it must be a multiple of the given value.
  • "maximum" - If the JSON instance is a number, it must be less than or equal to the given value.
  • "exclusiveMaximum" - If the JSON instance is a number, it must be less than the given value.
  • "minimum" - If the JSON instance is a number, it must be greater than or equal to the given value.
  • "exclusiveMinimum" - If the JSON instance is a number, it must be greater than the given value.
  • "maxLength" - If the JSON instance is a string, its length must be less than or equal to the given value.
  • "minLength" - If the JSON instance is a string, its length must be greater than or equal to the given value.
  • "pattern" - If the JSON instance is a string, it must result a match for the given regular expression.
  • "items" - If the JSON instance is an array, its elements must be valid against given schemas.
  • "additionalItems" - If the JSON instance is an array, and it have more elements than what "items" provides, additional elements are validated against the given schema.
  • "maxItems" - If the JSON instance is an array, the number of its elements must be less than or equal to the given value.
  • "minItems" - If the JSON instance is an array, the number of its elements must be greater than or equal to the given value.
  • "uniqueItems" - If the JSON instance is an array, the uniqueness of its elements must match the given boolean value
  • "contains" - If the JSON instance is an array, it must contains at least one element that is valid against the given schema.
  • "maxProperties" - If the JSON instance is an object, the number of its properties must be less than or equal to the given value.
  • "minProperties" - If the JSON instance is an object, the number of its properties must be greater than or equal to the given value.
  • "required" - If the JSON instance is an object, it must have properties listed in the given array.
  • "properties" - If the JSON instance is an object, its properties must be valid against the schema in the given object of the same property name.
  • "patternProperties" - If the JSON instance is an object, its properties must be valid against the schema in the given object of the property name with matching regular expression.
  • "additionalProperties" - If the JSON instance is an object, its properties, that could not find its schema in "properties" and "patternProperties" keywords, must be valid against the given schema.
  • "dependencies" - If the JSON instance is an object and it has a property that matches a given property, that property must satisfy the given dependency condition.
  • "propertyNames" - If the JSON instance is an object, all property names of the object must be valid against the given schema.
  • "enum" - The JSON instance must match one of the elements in the given array.
  • "const" - The JSON instance must match the given value.
  • "type" - The JSON instance must be one of the given JSON types.
  • "allOf" - The JSON instance must be valid against all schemas in the given array.
  • "anyOf" - The JSON instance must be valid against at least one schema in the given array.
  • "oneOf" - The JSON instance must be valid against at exactly one schema in the given array.
  • "not" - The JSON instance must be invalid against the given schema.

 

JSON Schema Validation for JSON Number Values

JSON Schema Syntax

Introduction of JSON Schema

⇑⇑ JSON Tutorials

2017-09-01, 1570🔥, 0💬