JSON Schema
How data.validate checks a payload against a JSON Schema (draft-07) — the ports it opens, what the validator accepts, and the strict rules that make a schema fail before it validates anything.
data.validate checks its input against a JSON Schema and routes the run by the result.
Put it right after a trigger or an extraction to stop bad data before it reaches a system of record.
Ports
| Port | When |
|---|---|
valid | The input matches the schema. |
invalid | The input does not match. The run continues on this branch. |
error | The schema itself could not be read or compiled. |
On valid and invalid the input passes through unchanged. The validation errors are recorded with the node’s
execution, so you see them in the run. Connect invalid to the path that handles bad data: a reply to the sender, a
task for a person, or a log.
Write the schema
The schema field takes a JSON Schema object. The validator is Ajv 8 with draft-07:
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"required": ["body"],
"properties": {
"body": {
"type": "object",
"required": ["email", "amount", "status"],
"properties": {
"email": { "type": "string", "pattern": "^[^@\\s]+@[^@\\s]+\\.[^@\\s]+$" },
"amount": { "type": "number", "minimum": 0 },
"status": { "enum": ["open", "closed"] },
"items": {
"type": "array",
"minItems": 1,
"items": { "type": "object", "required": ["sku"] }
}
},
"additionalProperties": false
}
}
}Every draft-07 keyword except format works (see below): type, required, properties, enum, const, pattern, minimum,
minLength, items, additionalProperties, if / then / else, allOf, anyOf, oneOf and the rest. All
errors are reported, not only the first one.
Strict rules
The validator runs in strict mode, so some schemas fail to compile and the node leaves through error:
| Fails | Write instead |
|---|---|
"format": "email" (or date, uri…) | A pattern, such as the email pattern above, or ^\d{4}-\d{2}-\d{2}$ for a date |
Unknown keywords, such as "example" | "examples": [ … ], "title" and "description" are allowed |
"$schema" of draft 2019-09 or 2020-12 | The draft-07 URI, or no $schema |
Other places that use JSON Schema
Apps declare their input and output with JSON Schema contracts; see contracts.