Ajv compiles JSON Schemas into validation functions for Node.js and browsers. It supports multiple JSON Schema drafts and JSON Type Definition (RFC 8927).
Overview
Ajv is a validator that turns JSON Schema and JSON Type Definition documents into functions that check JSON data. It targets Node.js and browser environments, including Electron and similar JavaScript runtimes.
The library covers standard validation keywords, remote schema references, recursive references, nullable and discriminator keywords, and JTD schema forms including union and user-defined keywords. It can report all errors at once, coerce types, assign defaults, remove additional properties, and support custom formats and keywords, including asynchronous validation.
Schemas compile to optimized JavaScript for runtime checks. A command-line interface is available, and documentation covers strict mode, standalone validation code generation, and security considerations.
Ajv is used widely in JavaScript applications and tools for configuration and data validation.
Key features
- JSON Schema drafts 04 through 2020-12
- JSON Type Definition (RFC 8927)
- Remote and recursive schema references
- Custom and user-defined keywords
- $data references from validated data
- All-errors validation mode
- Type coercion and default assignment
- Command-line interface
Use cases
- Validating API request and response bodies
- Checking configuration files
- Enforcing data shapes in Node.js services
- Client-side form and payload validation