API Reference

Ajv

Fast JSON Schema validator for JavaScript with draft-07 support and keyword extension.

Official Documentation ↗
CompatibilityThis documentation covers version v8.17. Check the official docs for the latest API surface.

Installation

npmnpm install ajv
pnpmpnpm add ajv
yarnyarn add ajv

Methods

Ajv is a fast JSON Schema validator for JavaScript. It compiles schemas to optimized validation functions, supports references, custom keywords, and async validation, and is used by Fastify and many tools.

Key Features

  • Fast: Schema compilation to JS functions
  • Standards: JSON Schema draft-07 and 2019-09
  • References: $ref with shared schemas and recursion
  • Custom keywords: Extend validation with domain rules
  • Errors: Detailed, structured error objects

FAQ

How fast is Ajv and why?
Ajv compiles schemas to JavaScript functions at build time, then runs them with minimal overhead. It is among the fastest JSON Schema validators, often faster than hand-written validation for complex schemas.
Which JSON Schema draft does Ajv support?
Ajv 8 supports draft-07 and draft-2019-09 via separate exports. For draft-04, use Ajv with the ajv-formats and draft-04 legacy package. Choose the export matching your schema draft.
How do I use formats like email or uri?
Formats are not validated by default for security. Import ajv-formats and call addFormats(ajv) to enable email, uri, date, and others, or define custom format checks with ajv.addFormat.