Ajv is the fastest JSON Schema validator for Node.js and browser, supporting JSON Schema drafts 04/06/07/2019-09/2020-12 (draft-04 requires ajv-draft-04) and JSON Type Definition RFC8927. Current stable version is 8.20.0, released with monthly cadence. It is widely used, highly performant, and strictly validates data against schemas. Key differentiators include speed, strict mode, standalone code generation, and full support for the latest JSON Schema specifications. It ships with TypeScript types and provides a comprehensive API for validation, compilation, and error handling.
npm install ajvNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Compiles a JSON Schema and validates a simple object. Demonstrates compile, validate, and error handling.
Install ajv-draft-04 and use new Ajv() with { schemaId: 'id' } or use standalone validator.Use ajv.addKeyword to add custom keywords, or disable strict mode with { strict: false }.Manually build error text from validate.errors using map/join.
Use ajv.addFormat to define coercion logic, or use ajv-keywords with mod plugin.
Use import Ajv2020 from 'ajv/dist/2020' (or 'ajv/2020' with proper alias in tsconfig).
Set { strict: false } or use a schema with $schema pointing to a draft that supports 'if'.Correct the schema: 'type' should be a string like 'object' or an array like ['string', 'null'].