1. License
“Permission is hereby granted, free of charge, to any person obtaining a copy”
MIT allows use in paid and closed-source apps.
github.com/ajv-validator/ajv/blob/master/LICENSE3. Used by agents' projects
Dependency in 154 public GitHub projects set up for AI coding agents that we scanned (2.5%).
4. Agent access
Agent skills for this library in the skills catalog; community skills are written by others, read them before you install.
From the package registry and GitHub, checked daily; card checked Nov 10, 2026. Tap a verdict to see its source.How we checkedReport an error
What Ajv does
Ajv is a free JavaScript library that checks whether incoming data has the shape you expect, such as a sign-up form or a request to your server. You describe the rules once in a JSON Schema file. Ajv turns them into a fast check and tells you exactly which field is wrong and why.
What people build with it
Check what reaches your server
Before your app saves a new order or sign-up, it checks the data against one set of rules and refuses anything with missing or wrong fields.
Show every form mistake at once
A sign-up form lists all problems together, such as a bad email and a too-young age, instead of one at a time.
Fill in defaults, drop extras
When a request leaves out the plan, it becomes "free"; fields you never asked for, like an admin flag, are removed before you save.
Check JSON from an AI model Idea
When you ask an AI model for JSON, check the answer against your rules before your app uses it, and ask again if it fails.
Strict pages without eval
If your site's security settings block code built on the fly, compile the checks while you build the site and ship them as plain files.
Catch typos in settings files Idea
Check a settings file people edit by hand when your tool starts, and name the line that is wrong instead of failing later.
Ajv popularity
Gid Score measures public popularity and activity, not quality. How the Gid Score is calculated
How Ajv is used
- Ajv is a dependency in 154 of the 6,258 public GitHub projects set up for AI coding agents that we scanned (3.2% of the 4,867 JavaScript/TypeScript ones), #5 of 63 in forms, validation and schemas.
- Counting the projects our scan samples by dependency (Solana 3,067, Ethereum and EVM 1,774, 3D and games 3,130, agent frameworks and SDKs 13,750), it appears in 453; those are left out of every share on this page.
- The most used alternative in our scan is Zod (1,582 projects).
- Projects that use it most often also use ajv-formats (37.7%), yaml (31.8%), Commander (30.5%).
- It is more common in projects set up for Kiro (14.3%) than for Cursor (1.8%).
By coding agent
Often used with
Ajv in practice
Strengths
Ajv does not interpret a schema on each call. The README says it generates code from the schema and produces validation functions that suit V8's optimizer.
The README calls Ajv the fastest and most standard-compliant validator "according to these benchmarks". It lists json-schema-benchmark, where it reports Ajv as 50% faster than second place, along with the jsck, z-schema and themis benchmarks.
You can write schemas in either JSON Schema or JSON Type Definition. The getting-started guide says the two have "different advantages and disadvantages" and points to a separate page on choosing between them.
From a JTD schema, Ajv can build a parser and a serializer specialized to your data shape. The docs say serializing this way "can be more than 10x compared with <code>JSON.stringify</code>". They also say invalid JSON fails much faster than with generic parsing.
Watch out for
Running a compiled validator is fast, but building one is not. The docs tell you to compile each schema once and reuse the function. Ajv caches compiled functions and uses the schema object as the key.
The next validation replaces the <code>errors</code> property. If you need the errors later, for example in a callback, copy the array reference to another variable first.
The FAQ says returning a boolean is a deliberate choice, made for history and performance. The maintainers answer "No" to adding a method that returns errors. They suggest putting any API you prefer in your app's own validation module.
Compile a schema and validate an object
// or ESM/TypeScript import
import Ajv from "ajv"
// Node.js require:
const Ajv = require("ajv")
const ajv = new Ajv() // options can be passed, e.g. {allErrors: true}
const schema = {
type: "object",
properties: {
foo: {type: "integer"},
bar: {type: "string"},
},
required: ["foo"],
additionalProperties: false,
}
const data = {
foo: 1,
bar: "abc",
}
const validate = ajv.compile(schema)
const valid = validate(data)
if (!valid) console.log(validate.errors)More about Ajv
Funding
- GitHub Sponsors: https://github.com/epoberezkin
- Tidelift: https://tidelift.com/funding/github/npm/ajv
- Open Collective: https://opencollective.com/ajv
- 15 GitHub sponsors
Head to head
- Zod vs Ajv used together in 79 projects
Packages around it
- ajv-formats: Format validation plugin for Ajv
- jsdom: DOM implementation for Node.js
- prettier: Code formatter
- jest: Test runner
- vitest: Test runner
- @modelcontextprotocol: Model Context Protocol SDK
More in Forms, validation and schemas
Alternatives
Ajv This page
Pick Zod when you write TypeScript and want to declare the rules in code and get matching types, rather than keep JSON Schema files.
Pick jsonschema when the same JSON Schema checks have to run in a Python app.
Pick Pydantic when your app is Python and you want data models with checks built from type hints.
Modular and type-safe schema validation library for structural data with minimal bundle size.
JSON Schema type builder with static type resolution for TypeScript validation.
Simple schema validation library for JavaScript with chainable API and error handling.
Get started
Tell your AI assistant
“Use Ajv (pin ajv@8.20.0, plus ajv-formats@3.0.1 for email and date formats) to check request bodies against a JSON Schema; compile each schema once at startup and return validate.errors as a 400 response.”
Install version 8 into your project (the older draft-04 schemas need version 6).
npm install ajvCompile a schema once, then call the returned function on each piece of data; read validate.errors when it returns false.
// or ESM/TypeScript import import Ajv from "ajv" // Node.js require: const Ajv = require("ajv") const ajv = new Ajv() // options can be passed, e.g. {allErrors: true} const schema = { type: "object", properties: { foo: {type: "integer"}, bar: {type: "string"}, }, required: ["foo"], additionalProperties: false, } const data = { foo: 1, bar: "abc", } const validate = ajv.compile(schema) const valid = validate(data) if (!valid) console.log(validate.errors)Add ajv-formats if your schema uses formats such as email, date or uri.
npm install ajv-formats
Rules for your agent
## Ajv
- Compile each schema only once and reuse the compiled validation function. The docs say compilation is relatively slow and that the best performance comes from functions returned by `compile` or `getSchema`.
- Copy the `validate.errors` array reference to another variable if you need it later. Every validation call overwrites it.
- `properties` alone does not require any keys or an object type. Use `required` for keys and `type` for the type.
- `additionalProperties: false` only considers `properties` and `patternProperties` in the same schema object. Properties declared inside `oneOf`/`anyOf` subschemas count as additional.
- Add the `ajv-formats` plugin for `format` keywords. Add remote schemas with `addSchema` or compile them so `$ref` can resolve them.
- Compiled JTD parsers return `undefined` instead of throwing. Check the return value and read the parser's `message` and `position` properties.
- Do not put validated data into logged error messages. Take property names from the error's `params` object when you build your own messages.
Mistakes to avoid
The default class is for draft-07; in our run it threw "strict mode: unknown keyword: prefixItems", and Ajv2020 accepted the same schema.
Formats moved out of Ajv in version 7; in our run compile threw unknown format "email".
Ajv 8 renamed the error field, so old code silently gets undefined.
Compiling is the slow part; running a compiled check is fast.
Each call overwrites the errors property.
Questions
Can I use Ajv in a paid, closed-source app?
Yes. It is MIT licensed; keep its copyright and license notice in copies you ship.
Does it work in the browser?
Yes, in browsers and in Node.js 18 and newer. Pages with a strict security policy should ship checks compiled ahead of time.
Why does my schema with format "email" throw an error?
Formats are not built into Ajv 8. Add the ajv-formats plugin, or the schema fails to compile.
My old schemas use draft-04. Which version do I need?
Ajv 6. Version 8 supports draft-06 and newer.
Why does Ajv reject a schema with an extra keyword like "placeholder"?
Strict mode is on by default and stops on keywords it does not know. Declare them with addKeyword or turn strict mode off.