not : Schema

not

Schema

An instance is valid against this keyword if it fails to validate successfully against the schema defined by this keyword.

Value This keyword must be set to a valid JSON Schema
Kind Applicator
Applies To Any
Base Dialect 2020-12
Changed In None
Introduced In Draft 4
Vocabulary Applicator
Specification https://json-schema.org/draft/2020-12/json-schema-core.html#section-10.2.1.4
Metaschema https://json-schema.org/draft/2020-12/meta/applicator
Official Tests draft2020-12/not.json
Default false
Annotation None
Affected By None
Affects None
Also See

The not keyword restricts instances to fail validation against the given subschema. This keyword represents a logical negation (NOT) operation. In other words, the instance successfully validates against the schema only if it does not match the given subschema.

This keyword is equivalent to the ! operator found in most programming languages. For example:

bool valid = !not_schema;

Examples

A schema that constrains instances to not be a specific value Schema
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "not": {
    "title": "I will never be emitted as an annotation",
    "const": "Prohibited"
  }
}
Valid A value that does not equal the prohibited value is valid and no annotation is emitted Instance
"Hello World"
Invalid A value that equals the prohibited value is invalid Instance
"Prohibited"
A schema that negates an unsatisfiable schema matches every possible instance Schema
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "not": {
    "type": "string",
    "minLength": 10,
    "maxLength": 9
  }
}
Valid Any value is valid Instance
"Hello World"