Schema Composition
JSON Schema lets you combine multiple subschemas on a single field using allOf, anyOf, oneOf, and not.
allOf (AND)
The value must be valid against all of the given subschemas.
Activation Conditions
allOfkeyword present — the field still renders with its own type's normal editor; every subschema is validated together.
Example
{
"type": "string",
"title": "Username (allOf)",
"allOf": [
{
"minLength": 3
},
{
"pattern": "^[a-z0-9_]+$"
}
]
}anyOf (OR)
The value must be valid against any (one or more) of the given subschemas.
Activation Conditions
anyOfkeyword present — jedison shows a switcher to pick which candidate schema to fill in as.
Example
{
"type": "number",
"title": "Number (anyOf)",
"anyOf": [
{
"type": "number",
"multipleOf": 3
},
{
"type": "number",
"multipleOf": 5
}
]
}oneOf (XOR)
The value must be valid against exactly one of the given subschemas — matching more than one is invalid too.
Activation Conditions
oneOfkeyword present — uses the same switcher UI asanyOf.
anyOf vs. oneOf
Try 15 in both this example and the anyOf example above: 15 is a multiple of both 3 and 5, so it's valid for anyOf but invalid for oneOf.
Example
{
"type": "number",
"title": "Number (oneOf)",
"oneOf": [
{
"type": "number",
"multipleOf": 3
},
{
"type": "number",
"multipleOf": 5
}
]
}not (NOT)
The value must not be valid against the given subschema.
Activation Conditions
notkeyword present — adds a validation rule on top of the field's normal editor; it doesn't change which editor is used.
Example
{
"type": "string",
"title": "Username (not)",
"not": {
"const": "admin"
}
}