
Ajv
A fast library that checks whether JSON data matches a schema, for Node.js and browsers.
- Stars
- 14.9k
- Forks
- 1.1k
- Licence
- MIT
- Language
- TypeScript
- Last update
- 2 months ago
- Type
- Library
What it is
Ajv is a JavaScript/TypeScript library that checks JSON data against a schema, such as confirming a form submission or API request has the required fields and types. It supports JSON Schema drafts 04, 06, 07, 2019-09 and 2020-12, plus JSON Type Definition (RFC 8927). The README describes it as fast, and it generates validation code from schemas to achieve this.
- Validate incoming JSON in an Express or similar server before processing it
- Check configuration files against a schema on startup
- Generate standalone validation code for use in a build step (README mentions standalone validation code)
- Use the command line interface (ajv-cli) to validate JSON files
Great for
- Node.js developers validating API request or response bodies
- Front-end developers validating form or config data in the browser
- Teams already writing JSON Schema who need a standards-based checker
- Projects that need draft-04 support (via the separate ajv-draft-04 package)
Not ideal for
- People who are new to programming and just want a simple form library, since it requires writing schemas
- Projects that need a non-JavaScript runtime, since the README only mentions Node.js and browsers
- Users who only need to check a few values by hand, where a simple function would be enough
How to get it
- 1
Install with a package manager
You'll need: Node.js
Install the package
npm install ajv - 2
Run it
- Install the package with npm install ajv
- Import Ajv and create a new instance
- Compile a JSON Schema into a validation function
- Call the validation function on your JSON data and check the result
- 3
Get the most out of it
- Read the strict mode documentation to catch schema mistakes early
- Use standalone validation code to avoid compiling schemas at runtime
- Install ajv-cli for command line validation of JSON files
- Check the security considerations page on the Ajv website
Downloads
Strengths
- The README claims it is the fastest JSON schema validator and cites third-party benchmarks
- Supports multiple JSON Schema drafts and JSON Type Definition
- MIT licensed with a large community (over 100 contributors per the README)
Trade-offs
- Draft-04 support requires an extra package, so setup is not one step for older schemas
- The README is short and points to an external website for most documentation
- Performance claims come from the project's own README citing older benchmarks
How it compares
| Project | Stars | Type | Level | Updated | Best for |
|---|---|---|---|---|---|
| ajv (this) | 14.9k | Library | intermediate | 2 months ago | Node.js developers validating API request or response bodies |
| zod | 44.2k | Library | beginner | 6 days ago | TypeScript developers who want runtime checks that match their static types |
| formily | 12.6k | Library | intermediate | 1.4 years ago | Frontend developers building data-heavy forms with many linked fields |
| pydantic | 29.3k | Library | beginner | 4 days ago | Python developers who already use type hints and want runtime checks on incoming data |
| validator.js | 23.7k | Library | beginner | 2 months ago | JavaScript developers validating form or API input on Node.js |
| class-validator | 11.9k | Library | beginner | 8 months ago | TypeScript developers validating request bodies or form data in Node.js or the browser |
Stats synced from GitHub. The assessment above was drafted with AI from the project's README on 2026-10-29 and may miss recent changes — check the README before relying on a command. MIT licence: free to use, modify and distribute, including commercially, as long as you keep the copyright notice.