Json Validator icon

Json Validator

A node json validator using Ajv (Another JSON validator)

Json Validator

AI-generated

Overview

This node validates JSON data against a user-defined JSON Schema using the Ajv library (Another JSON Validator). It is useful in workflows where you need to ensure that incoming JSON data conforms to a specific structure or set of rules before further processing. For example, it can be used to validate API responses, user inputs, or any JSON payloads to catch errors early and enforce data integrity.

Practical examples:

  • Validating that an incoming webhook payload contains required fields with correct types.
  • Ensuring that data extracted from previous nodes matches expected formats before saving to a database.
  • Checking configuration objects for completeness and correctness in automation workflows.

Properties

Name Meaning
Data Path to Validate The name of the field within the input JSON containing the data to validate. This field must hold a valid JSON object. Example values: output, data, payload, json. If left empty, the entire input JSON will be validated.
JSON Schema A JSON Schema definition describing the validation rules. You provide this schema as a JSON object. It defines the expected structure, required properties, types, and other constraints. Examples and documentation can be found at https://ajv.js.org/ or https://JSON-schema.org/.

Output

The output consists of items corresponding to each input item:

  • For each input item, if the data passes validation, the output JSON contains the validated data (either the whole input JSON or the specified subfield).
  • If validation fails for an item:
    • If "Continue On Fail" is enabled, the output JSON contains an error field with detailed validation errors and a message describing which item failed and why.
    • Otherwise, the node throws an error and stops execution.

No binary data is produced by this node.

Dependencies

  • Requires the Ajv library for JSON Schema validation.
  • No external API keys or services are needed.
  • No special environment variables or n8n credentials are required.

Troubleshooting

  • Common issues:

    • Invalid or malformed JSON Schema: The node will throw an error if the provided schema cannot be parsed or compiled.
    • Input data not matching the schema: Validation errors will indicate which properties failed and why.
    • Incorrect "Data Path to Validate": If the specified path does not exist or does not contain valid JSON, validation will fail.
  • Error messages:

    • "Invalid JSON Schema": Indicates the JSON Schema provided is not valid JSON or does not compile correctly. Check the schema syntax and structure.
    • "Validation failed for item X: ...": Shows detailed reasons why the input data did not conform to the schema for item number X. Review the schema requirements and input data format.
  • To resolve errors, verify the JSON Schema correctness using online validators or the Ajv documentation, and ensure the input data path is correctly specified.

Links and References

Discussion