Flagbit Data Validation

Validate input data before continuing the workflow

Overview

This node validates incoming JSON data against a user-defined JSON Schema before allowing the workflow to continue. It is useful in scenarios where you want to ensure that input data conforms to specific structural and content rules, preventing invalid or malformed data from propagating through your automation.

For example, if you expect an object with an integer property foo and an optional string property bar, this node can enforce those constraints. If the data does not match the schema, the node appends detailed validation errors to the output, enabling downstream nodes to handle or log these issues appropriately.

Properties

Name Meaning
JSON Schema A JSON Schema definition describing the expected structure and validation rules for the input data. You can define required properties, types, allowed values, and more. See https://ajv.js.org/ or https://json-schema.org/ for guidance on writing schemas.

Output

The node outputs the original input data augmented with validation results:

  • The json field contains the original input JSON.
  • If validation fails, an additional errors property is added inside the json output. This errors array includes objects with:
    • message: Description of the validation error.
    • schemaPath: The location within the schema where the error occurred.
    • params: Additional parameters related to the error.

If the input item contains binary data, it is passed through unchanged.

Dependencies

  • Uses the ajv library for JSON Schema validation.
  • Uses ajv-errors to enhance error reporting.
  • Requires the user to provide a valid JSON Schema as a string input property.

No external API keys or services are needed. The node runs entirely within the n8n environment.

Troubleshooting

  • Invalid JSON Schema: If the provided JSON Schema is not a valid JSON string or cannot be compiled by the validator, the node will throw an error stating "Invalid JSON Schema". To fix this, ensure your schema is correctly formatted JSON and follows JSON Schema standards.
  • Validation Errors in Output: When input data does not conform to the schema, the node does not fail but instead adds an errors array to the output JSON describing each validation issue. Use this information to debug or conditionally branch your workflow.
  • Empty or Missing Input Data: If input data is missing required fields as per the schema, validation will fail accordingly.
  • Binary Data Handling: Binary data is preserved and passed through without modification. Ensure that your schema only describes the JSON part of the input.

Links and References

Discussion