Validation keywords - sgpinkus/json-schema GitHub Wiki

THIS WIKI IS OBSOLETE. PLEASE SEE THE NEW JSON-SCHEMA-ORG/JSON-SCHEMA-SPEC REPOSITORY.


NOTE: This document refers to Draft 03 and will not be updated.


Foreword

In this page, you will find links to all currently existing defined validation keywords, and notes on the validation process itself.

Primitive types defined by JSON Schema

JSON Schema defines the following primitive types (in alphabetical order):

  • array: any JSON array;
  • boolean: JSON values true and false;
  • integer: this is not defined in the JSON RFC per se; an integer is a numeric instance with no decimal part;
  • number: this is any JSON numeric instance (therefore, with or without a decimal part, which means every "integer" is also a "number");
  • null: the single JSON value null;
  • object: any JSON object;
  • string: any JSON string.

Some keywords only apply to a defined set of primitive types, while other keywords apply to all instances. Sections below sort keywords according to this criterion.

Validation algorithm

The validation algorithm is as follows:

  • try and validate the current instance against all relevant keywords;
  • if the instance fails to validate against one of these keywords, validation is considered a failure and stops;
  • if the instance is not a container instance (an array or an object), then validation stops;
  • otherwise, for each child of the instance (array element, or object member value):
    • determine the set of schema(s) this child instance must validate against;
    • restart the validation process from the first step for each child.

This has a particular influence on the description of keywords as you will see below. For example, this is why items and additionalItems are covered in the same section: items in and of itself has no role into validating the array instance itself, only its elements. However, additionalItems does have an influence on validating an array, and this role depends on the value of items.

Validating keywords sorted by instance type

Preliminary notes

If the type (as defined by JSON Schema) of the instance to validate is not one of the primitive types to which a particular keyword applies, then validation with regards to that keyword succeeds.

Some keywords also have no meaning in the absence of other keywords: in this case, both will be covered in the same section.

Each page describes:

  • the valid values for a particular keyword, or set of keywords;
  • how to determine if an instance is valid against that keyword, or set of keywords.

Numeric instances (number and integer)

The following keywords apply to numeric instances:

  • divisibleBy;
  • [maximum and exclusiveMaximum](maximum and exclusiveMaximum);
  • [minimum and exclusiveMinimum](minimum and exclusiveMinimum).

String instances

The following keywords apply to string instances:

Array instances

The following keywords apply to array instances:

Object instances

The following keywords apply to object instances:

Any instance type

The following keywords do not apply to any instance type in particular:

Validation of array elements/object member values

This is an entire topic by itself, since the algorithm to determine these is not obvious.

It is easier for arrays, since an element will only have one schema to validate against. Not so with objects!

Read on below:

⚠️ **GitHub.com Fallback** ⚠️