Example 1: Closed object contract
Use this when payload shape is fixed and unknown keys should fail.
{
"type": "object",
"required": ["id", "active"],
"additionalProperties": false,
"properties": {
"id": {"type": "string"},
"active": {"type": "boolean"}
}
}
Example 2: Dynamic map keys with regex
Use this for dictionary-like objects where key names must follow a pattern.
{
"type": "object",
"patternProperties": {
"^[a-z0-9_-]+$": {"type": "string"}
},
"additionalProperties": false
}
Example 3: Conditional requirements (if/then/else)
{
"type": "object",
"required": ["playerType"],
"properties": {
"playerType": {"type": "string", "enum": ["warrior", "merchant"]},
"level": {"type": "integer"}
},
"if": {
"properties": {"playerType": {"enum": ["warrior"]}}
},
"then": {
"required": ["level"],
"properties": {"level": {"minimum": 1}}
}
}
Example 4: Format + numeric constraints
{
"type": "object",
"required": ["email", "coins"],
"properties": {
"email": {"type": "string", "format": "email"},
"coins": {"type": "integer", "multipleOf": 10, "minimum": 0}
}
}
Example 5: Skript debug loop
validate yaml "plugins/Schema-Validator/examples/simple-block-example.yml" using schema "plugins/Schema-Validator/examples/schemas/simple-block-schema.json"
set {_errors::*} to last schema validation errors
if size of {_errors::*} is 0:
broadcast "Validation passed"
else:
loop {_errors::*}:
broadcast "- %loop-value%"
Failure-first debugging workflow
- Start from a known valid data file.
- Introduce one controlled invalid value.
- Validate and capture
_errors::*. - Fix exactly one error at a time.
- Repeat until error list is empty.
Repository examples worth reusing
src/main/resources/examples/schemas/simple-block-schema.jsonsrc/main/resources/examples/schemas/conditional-validation.schema.jsonsrc/main/resources/examples/schemas/data-types-formats.schema.json
Related pages
- Full keyword support: Schema keywords
- Full runtime order: Validation behavior
- All supported formats: Format reference