Skip to main content

Validating form definitions

You can perform a static validation of a form definition using the JSON Schema. To implement validation, you need a validator for the language or framework you are using. For example, if you use Node.js you can use Ajv or Hyperjump to validate a form definition.

📥 Download JSON Schema for IDefinition

tip

There is a list of validators on the JSON Schema website.

👩‍💻 Example

The following example shows how to set up validation using the JSON Schema.

// Make sure to install ajv first: `npm i ajv`
import Ajv from "ajv";

// Download the schema for the Tripetto form definition and make it available to your code
import tripettoFormDefinitionSchema from "tripetto.schema.json";

const ajv = new Ajv({
allowUnionTypes: true,
validateSchema: false
});

const validate = ajv.compile(tripettoFormDefinitionSchema);

// Now you can validate a form definition
if (validate(/* Supply your form definition here */)) {
// All good!
}

Run Try on CodeSandbox