Yup Data Validator icon

Yup Data Validator

Yup Data Validator Node

Overview

The "Yup Data Validator" node validates JSON data against user-defined JSON Schemas using the Yup validation library. It is designed to ensure that input data conforms to specified structural and content rules before further processing in an n8n workflow.

Common scenarios where this node is beneficial include:

  • Validating API responses or webhook payloads to ensure they meet expected formats.
  • Enforcing data integrity before saving to databases or sending to other services.
  • Implementing complex conditional validations on incoming data items.

For example, you might use this node to validate that a customer record contains required fields like email and phone number formatted correctly, or to check that nested objects conform to a specific schema.

Properties

Name Meaning
Validations A collection of one or more validation rules. Each rule includes:
- Field Value: The JSON data to validate. This can be a field from the input item or any JSON object.
- Validation Schema: A JSON Schema defining the structure and constraints the Field Value must satisfy.

Output

The node outputs the original input items if all validations pass. If a validation fails and the node is configured to continue on failure, it outputs the item with an added error property containing the validation error message.

The output structure for each item is:

{
  "json": {
    ...originalItemData,
    "error": "Validation error message (only present if validation failed and continueOnFail is true)"
  },
  "pairedItem": {
    "item": <index of the original item>
  }
}

No binary data is produced by this node.

Dependencies

  • Uses the schema-to-yup package to convert JSON Schemas into Yup validation schemas.
  • Requires the Yup validation library indirectly via schema-to-yup.
  • No external API keys or services are needed.
  • No special environment variables or n8n credentials are required.

Troubleshooting

  • Common issues:

    • Invalid JSON in either the Field Value or Validation Schema properties will cause parsing errors.
    • Validation failures occur when the data does not conform to the provided JSON Schema.
    • If multiple validations are provided, all must pass for the item to be considered valid.
  • Error messages:

    • Validation errors will include detailed messages about which part of the data failed validation.
    • If continueOnFail is disabled, the node will stop execution on the first validation error.
    • To handle errors gracefully, enable the "Continue On Fail" option in the node settings.
  • How to resolve:

    • Ensure that the JSON Schema is correctly formatted and matches the expected structure of the data.
    • Verify that the Field Value JSON is valid and corresponds to the schema.
    • Use the error messages to adjust your schema or input data accordingly.

Links and References

Discussion