Skip to content
Agents tracked: 506 Releases (7d): 634 Agent status: 4 with issuesSince last limit reset: Claude 15d · Codex 0d For AI agents: Markdown Updated Nov 26, 2026

Ajv

Check JSON data against a schema in JavaScript.

Forms, validation and schemasNPM

GitHubWebsite

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/LICENSE

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

78 / 100
Gid Score, #141 overall
547M
downloads a week, npm
14.9K
GitHub stars
154
agent projects use it
Ajv: downloads per weeknpm, ajv 546,687,013
Ajv: GitHub starsajv-validator/ajv 14,885

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

109 projects, 3.3%
77 projects, 2.5%
45 projects, 1.8%
44 projects, 9.3%
37 projects, 11.1%
22 projects, 4.7%
20 projects, 14.3%
16 projects, 4.7%

Often used with

In 37.7% of its projects
In 31.8% of its projects
In 30.5% of its projects
In 29.9% of its projects
In 28.6% of its projects
In 27.9% of its projects
In 48.1% of its projects
In 40.3% of its projects

Ajv in practice

Strengths

Schemas become generated code

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.

Maintainers cite benchmarks for speed

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.

Pick JSON Schema or JTD

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.

JTD parsers and serializers

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

Compiling is the slow part

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.

<code>errors</code> is overwritten on every call

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.

No errors-returning method is coming

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

See all

Head to head
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

MITGid 78547M/wk

Zod

Pick Zod when you write TypeScript and want to declare the rules in code and get matching types, rather than keep JSON Schema files.

MITGid 89471M/wk

jsonschema

Pick jsonschema when the same JSON Schema checks have to run in a Python app.

Pydantic

Pick Pydantic when your app is Python and you want data models with checks built from type hints.

Valibot

Modular and type-safe schema validation library for structural data with minimal bundle size.

MITGid 6836M/wk

TypeBox

JSON Schema type builder with static type resolution for TypeScript validation.

MITGid 5817M/wk

Yup

Simple schema validation library for JavaScript with chainable API and error handling.

MITGid 6916.6M/wk

Compare Ajv with another tool

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.”

  1. Install version 8 into your project (the older draft-04 schemas need version 6).

    npm install ajv

    From github.com/ajv-validator/ajv/blob/master/README.md

  2. Compile 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)
    

    From ajv.js.org/guide/getting-started.html

  3. Add ajv-formats if your schema uses formats such as email, date or uri.

    npm install ajv-formats

    From ajv.js.org/guide/formats.html

Rules for your agent

Paste into AGENTS.md or CLAUDE.md
## 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

new Ajv() for a schema that uses draft 2020-12 keywords like prefixItems
const Ajv2020 = require("ajv/dist/2020"); new Ajv2020()

The default class is for draft-07; in our run it threw "strict mode: unknown keyword: prefixItems", and Ajv2020 accepted the same schema.

{type: "string", format: "email"} with a bare new Ajv()
const addFormats = require("ajv-formats"); addFormats(ajv) before compiling

Formats moved out of Ajv in version 7; in our run compile threw unknown format "email".

Reading err.dataPath from validate.errors (Ajv 6 code and old answers online)
Read err.instancePath (for example "/email"); messages now say "must" instead of "should"

Ajv 8 renamed the error field, so old code silently gets undefined.

Calling ajv.compile(schema) inside every request handler
Compile each schema once at startup and reuse the validate function

Compiling is the slow part; running a compiled check is fast.

Keeping a reference to validate.errors and reading it after the next validate() call
Copy the errors array right away if you need it later

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.