Skip to content

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
Step-by-step guide: how to use AjvInstall, first run, examples, tips and FAQs

How to get it

  1. 1

    Install with a package manager

    You'll need: Node.js

    Install the package

    npm install ajv
  2. 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. 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

ProjectStarsTypeLevelUpdatedBest for
ajv (this)14.9kLibraryintermediate2 months agoNode.js developers validating API request or response bodies
zod44.2kLibrarybeginner6 days agoTypeScript developers who want runtime checks that match their static types
formily12.6kLibraryintermediate1.4 years agoFrontend developers building data-heavy forms with many linked fields
pydantic29.3kLibrarybeginner4 days agoPython developers who already use type hints and want runtime checks on incoming data
validator.js23.7kLibrarybeginner2 months agoJavaScript developers validating form or API input on Node.js
class-validator11.9kLibrarybeginner8 months agoTypeScript 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.