not : Schema

not

Schema

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

Kind Applicator
Applies To Any
Dialect 2020-12
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
Also see

The not keyword is used to declare that an instance only validates if it doesn’t validate against the given subschema. It is essentially a way to define a rule that an instance should not match.

  • The value of this keyword must be a valid JSON Schema.
  • The boolean false schema, can be thought as an alias to { not: {} }.

Annotations are dropped when an instance fails. Therefore, in the case of not, annotations are always dropped because:

  1. If the subschema of not passes (producing annotations), then not itself fails, resulting in the annotations being dropped.
  2. If the subschema of not fails, no annotations are produced, and there is nothing for not to pass on.

Examples

Schema with 'not' keyword Schema
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "not": {
    "type": "string"
  }
}
An instance with values other than string is valid Instance
77
An instance with a string value is invalid Instance
"foo"
Schema with 'not' set to false Schema
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "not": false
}
Any instance is valid against the above schema Instance
{ "foo": "bar" }
  • Since the boolean false schema is equivalent to { "not": {} }, the overall schema translates to { "not": { "not": {} } }, which is equivalent to an empty object schema ({}). Therefore, every instance passes against the above schema.