Overview
The Data Validation node is designed to validate incoming data against a user-defined JSON Schema before allowing the workflow to continue. This ensures that only data conforming to specific structural and type requirements proceeds further in your n8n automation. Common scenarios include:
- Ensuring API responses or webhook payloads match expected formats.
- Validating user input before processing or storing it.
- Enforcing data integrity when integrating with external systems.
Practical Example:
If you expect each item to have an integer field foo and a string field bar, you can define this schema, and the node will halt execution (with an error) if any item does not comply.
Properties
| Display Name | Type | Description |
|---|---|---|
| JSON Schema | json | The JSON Schema definition used for validation. Visit ajv.js.org or json-schema.org to learn how to describe your validation rules in JSON Schemas. |
Details:
- The property expects a valid JSON Schema as a string.
- The default schema requires an object with:
- An integer property
foo(required). - A string property
bar. - No additional properties allowed.
- An integer property
Output
- json: Each output item contains the original input
jsonobject, unchanged, but only if it passed validation. - If any input item fails validation, the node throws an error and stops processing further items.
- No binary data is produced by this node.
Example Output:
[
{
"json": {
"foo": 123,
"bar": "example"
}
}
]
Dependencies
- External Library: ajv is used internally for JSON Schema validation.
- No external services or API keys are required.
Troubleshooting
Common Issues:
Invalid JSON Schema:
- Error:
"Invalid JSON Schema" - Cause: The provided schema is not valid JSON or does not conform to JSON Schema standards.
- Solution: Double-check your schema syntax and structure using online tools like JSON Schema Validator.
- Error:
Validation Errors:
- Error:
"Invalid data"with details about which fields failed validation. - Cause: Input data does not match the defined schema (e.g., missing required fields, wrong types).
- Solution: Review the error message for specifics and adjust your input data or schema accordingly.
- Error:
Type Mismatch:
- If the input data has types that do not match the schema (e.g., string instead of integer), validation will fail.