Validation60M+/wkMIT

ajv

Ajv (Another JSON Schema Validator) is the fastest JSON Schema validator for JavaScript and TypeScript, implementing the JSON Schema specification (drafts 04, 0

Installation

npm
npm install ajv
yarn
yarn add ajv
pnpm
pnpm add ajv

Import

ESM
import Ajv from 'ajv';

Quick Example

usage
import Ajv from 'ajv';
import addFormats from 'ajv-formats';

const ajv = new Ajv();
addFormats(ajv);

const schema = {
  type: 'object',
  properties: {
    name: { type: 'string', minLength: 1 },
    email: { type: 'string', format: 'email' },
    age: { type: 'integer', minimum: 0 },
  },
  required: ['name', 'email'],
};

const validate = ajv.compile(schema);
const valid = validate({ name: 'Alice', email: '[email protected]' });

About ajv

Ajv (Another JSON Schema Validator) is the fastest JSON Schema validator for JavaScript and TypeScript, implementing the JSON Schema specification (drafts 04, 06, 07, 2019-09, and 2020-12) with full compliance and exceptional performance. Ajv compiles JSON Schema into highly optimized validation functions at initialization time, making subsequent validations extremely fast — this compilation approach makes Ajv suitable for high-throughput scenarios like API request validation where the same schema is validated millions of times. The library supports all JSON Schema keywords including $ref for schema composition, if/then/else for conditional validation, allOf/anyOf/oneOf for combining schemas, pattern for regex validation, and format for built-in format checks (email, uri, date-time, uuid). Ajv provides plugins for additional formats (ajv-formats), custom keywords for extending the schema vocabulary, asynchronous validation for custom async checks, and schema coercion for automatic type conversion. The library generates human-readable error messages with full JSON Pointer paths to invalid data. Ajv is used internally by many tools and frameworks including ESLint, webpack, and various API frameworks for configuration and request validation. Ajv's JSON Schema compliance makes schemas portable across languages and tools that support the JSON Schema standard.

Quick Facts

Packageajv
CategoryValidation
Weekly Downloads60M+
LicenseMIT
Installnpm install ajv

Related Packages

Browse npm Packages by Category

Explore our reference of 200 popular npm packages with install commands, examples, and quick-start guides.