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
Hint: Use the jsonschema metaschema and jsonschema lint commands to catch keywords set to invalid values
|
---|---|
Kind | Applicator |
Applies To | Any |
Base Dialect | Draft 4 |
Changed In | None |
Introduced In | Draft 4 |
Vocabulary | Validation |
Specification | https://json-schema.org/draft-04/draft-fge-json-schema-validation-00#rfc.section.5.5.6 |
Metaschema | http://json-schema.org/draft-04/schema# |
Official Tests | draft4/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.
Best Practice
Avoid the use of this keyword (usually negating the
required
keyword) to prohibit
specific object properties from being defined. Instead, use the
properties
keyword and set
the disallowed object properties to the false
boolean
schema.
This keyword is equivalent to the !
operator found in most programming
languages. For example:
bool valid = !not_schema;
Examples
{
"$schema": "http://json-schema.org/draft-04/schema#",
"not": {
"const": "Prohibited"
}
}
"Hello World"
"Prohibited"
{
"$schema": "http://json-schema.org/draft-04/schema#",
"not": {
"type": "string",
"minLength": 10,
"maxLength": 9
}
}
"Hello World"