- What JSON Schema is and why it’s useful for form development
- How to generate a schema for your component library
- How to integrate the schema with your development environment
What is JSON Schema?
JSON Schema is a vocabulary that allows you to annotate and validate JSON documents. For FormEngine, a JSON Schema describes the complete structure of a form definition, including:- Allowed component types and their properties
- Property value types (string, number, boolean, etc.)
- Required fields and validation rules
- Component hierarchies and nesting rules
- Autocomplete for component types and properties
- Type checking for property values
- Error highlighting for invalid structures
- Documentation tooltips for component properties
Generating a JSON Schema
To generate a JSON Schema for your forms, you’ll use the createSchema function from the @react-form-builder/json-schema-generator package. This function analyzes your component library and creates a comprehensive schema.Basic Schema Generation
Here’s the simplest way to generate a schema:Schema with Component Descriptions
To include documentation in your schema, provide component descriptions:Custom Component Libraries
If you have a custom component library, generate a schema for it:Using the Schema in Your Development Workflow
Once you have a JSON Schema, you can integrate it into your development environment.Saving the Schema to a File
Save the generated schema to a file that you can reference in your projects:generate-schema.js
Configuring Your IDE
Most modern IDEs support JSON Schema validation. Here’s how to configure popular editors: VS Code (Zed, WebStorm/IntelliJ IDEA also support this approach): Add a$schema reference to your form JSON files:
my-form.json
Example: Basic Form with Schema Validation
This example shows a simple form that would be validated against a JSON Schema:user-form.json
- Autocomplete component types like
MuiTextFieldandMuiCheckbox - Validate that
props.labelhas avalueproperty - Check that validation keys like
requiredandemailare valid - Ensure the form structure follows the correct hierarchy
Schema Features and Capabilities
Component Type Validation
The schema validates that component types exist in your library:Property Type Checking
Each component property is validated for correct type:Nested Structure Validation
Component hierarchies are validated:Summary
- JSON Schema provides validation and autocomplete for form definitions
- Generate schemas with
createSchemafrom component libraries - Include component descriptions for better IDE documentation
- Reference schemas with
$schemaproperty in JSON files
For more information:
- Form JSON Structure - Learn about the JSON format for forms
- Custom Components - Create your own components
Next steps
- Form JSON — Understand form definition structure and properties
- Validation — Add validation rules to ensure data quality