The Validate action in the JSON package enables you to validate the contents of a JSON data source. You can use this action to validate the syntax, structure, and schema of any JSON source.

Overview

The Validate action enables you to check for any potential errors in the JSON data source before you pass it to any downstream actions. This action improves the reliability of the automation by preventing runtime failures and reducing debugging time. You can specify the JSON data source, set the validation levels, and save the validation results in multiple variables or a single dictionary variable.

The Validate action supports file streaming capability. You can use any file stream capable actions to create a file variable that holds the file stream and use the file variable as the JSON data source.

Validation levels

The following validation levels are available in this action:

Format
The Format option validates the JSON data source for syntax rules such as format and grammar. This option enables you to check the correct usage of JSON grammar rules such as curly brackets {}, square brackets [], colon :, commas ,, string double quotes, and JSON literals like true, false, and null.
This validation level is not available when you select a Dictionary variable as the data source.
Node
The Node option validates the JSON data source for structure rules such as the existence of a specific node and its correct datatype. This option enables you to check the existence of a node by specifying the node key or the node path. You must also specify the expected datatype of the specified node in the Value type drop down.
Schema
The Schema option validates if the JSON data source follows the specified schema definition. This option subsumes both Format and Node options as the JSON schema defines the JSON grammar, nodes, datatypes, required/optional fields, enum values, and maximum/minimum values.
Note: Ensure that you specify the JSON schema draft version in the schema definition file variable or the string. If you do not specify the version, the Validate action uses the JSON schema draft 2020-12 specification as the default option to validate the JSON data source.

Validation results

The Validate action enables you to save the validation results as individual variables or a single dictionary variable. The automation execution fails only if there is a platform failure such as the existence of the value Null in the JSON data source. The validation results are stored in the following keys:

isvalid
The isvalid key contains the validation result of the JSON source. The following are the potential values:
  • true: If the validation is successful.
  • false: If the validation fails.
validationlevel
The validationlevel key contains the validation level that you set when configuring the action. The following are the potential values:
  • syntax: If the validation level is set as Format.
  • structure: If the validation level is set as Node.
  • schema: If the validation level is set as Schema.
errorpath
The errorpath key contains the path in the JSON data source where the error is present.
error message
The error message key contains the error message. For example, if the JSON schema defines a number but the JSON data source provides a string at the same location, the error message key stores this string found, integer expected error message as its value.