not : Schema
not
SchemaAn 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 |
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 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 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:
- If the subschema of
not
passes (producing annotations), then not itself fails, resulting in the annotations being dropped. - If the subschema of
not
fails, no annotations are produced, and there is nothing for not to pass on.
Examples
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"not": {
"type": "string"
}
}
77
"foo"
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"not": false
}
{ "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.