then : Schema

then

Schema

When if is present, and the instance successfully validates against its subschema, then validation succeeds if the instance also successfully validates against this keyword’s subschema.

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 7
Vocabulary Applicator
Specification https://json-schema.org/draft/2020-12/json-schema-core.html#section-10.2.2.2
Metaschema https://json-schema.org/draft/2020-12/meta/applicator
Official Tests draft2020-12/if-then-else.json
Default {}
Annotation None
Affected By
Affects None
Also See

The then keyword restricts instances to validate against the given subschema if the if sibling keyword successfully validated against the instance.

Examples

A schema that constrains numeric instances to be positive when they are even numbers Schema
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "if": { "multipleOf": 2 },
  "then": { "minimum": 0 }
}
Valid An even number value that is positive is valid Instance
10
Invalid An even number value that is negative is invalid Instance
-2
Valid An odd number value that is positive is valid Instance
7
Valid An odd number value that is negative is valid Instance
-3
Valid A non-number value is valid Instance
"Hello World"
A schema that emits a simple annotation when a numeric value is even Schema
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "if": { "multipleOf": 2 },
  "then": { "title": "The value is an even number" }
}
Valid An even number value is valid and emits an annotation Instance
10
Annotations
{ "keyword": "/then/title", "instance": "", "value": [ "The value is an even number" ] }
Valid An odd number value is valid but does not emit an annotation Instance
5