Utils icon

Utils

Utils Node

Overview

This node provides utility functions, with a key operation to validate input JSON data against a user-defined JSON schema. It is useful when you want to ensure that incoming data conforms to a specific structure before further processing in your workflow. For example, you can verify that an object contains required fields of certain types or that arrays contain only strings.

Practical scenarios include:

  • Validating API responses to ensure they meet expected formats.
  • Checking user input data for correctness before saving to a database.
  • Enforcing data contracts between different parts of a workflow.

Properties

Name Meaning
Input Schema A JSON schema defining the expected structure and types of the input data. The node validates each input item against this schema.

The "Input Schema" property accepts a JSON object describing the schema. Example options include specifying object properties, their types (e.g., string, array), and nested structures.

Output

The output consists of the original input items that passed validation, unchanged in their JSON form.

If an item fails validation and the node is set to continue on failure, the output for that item will be an object containing:

  • json.error: A message describing the validation error.
  • json.errors: Detailed errors from the schema validator.
  • An error property with the full error object.

No binary data is produced by this node.

Dependencies

  • Uses the ajv library for JSON schema validation.
  • Requires no external API keys or services.
  • No special environment variables or n8n configurations are needed beyond standard node setup.

Troubleshooting

  • Common issues:
    • Invalid JSON schema syntax in the "Input Schema" property will cause parsing errors.
    • Input data not matching the schema will trigger validation errors.
  • Error messages:
    • "Input data does not match schema: ..." indicates the input JSON failed validation. Review the schema and input data for mismatches.
    • If the node is not set to continue on failure, it will stop execution on the first invalid item.
  • To resolve errors, ensure the schema is correctly formatted and accurately describes the expected input structure.

Links and References

Discussion