{
 "kind": "tool",
 "slug": "ajv",
 "path": "tools/ajv/",
 "name": "Ajv",
 "maker": null,
 "density": "full",
 "crumbs": [
  [
   "Tools",
   "tools/"
  ],
  [
   "Forms, validation and schemas",
   "tools/forms-validation/"
  ]
 ],
 "lead": "Check JSON data against a schema in JavaScript.",
 "chips": [
  {
   "label": "Forms, validation and schemas",
   "path": "tools/forms-validation/"
  },
  {
   "label": "NPM"
  }
 ],
 "primary": {
  "label": "Copy install command",
  "copy": "npm install ajv"
 },
 "links": [
  {
   "label": "GitHub",
   "href": "https://github.com/ajv-validator/ajv"
  },
  {
   "label": "Website",
   "href": "https://ajv.js.org"
  }
 ],
 "track": "New versions, deprecation and license changes on your dashboard",
 "verdicts": [
  {
   "key": "license",
   "label": "License",
   "value": "MIT",
   "status": "yes",
   "sub": "Use it in paid apps",
   "quote": "Permission is hereby granted, free of charge, to any person obtaining a copy",
   "note": "MIT allows use in paid and closed-source apps.",
   "src": "https://github.com/ajv-validator/ajv/blob/master/LICENSE"
  },
  {
   "key": "maint",
   "label": "Maintained",
   "value": "Maintained",
   "status": "yes",
   "sub": "Last change Sep 6, 2026",
   "note": "Latest GitHub release Apr 24, 2026. ",
   "src": "https://github.com/ajv-validator/ajv"
  },
  {
   "key": "pop",
   "label": "Used by agents' projects",
   "value": "154 projects",
   "status": "info",
   "sub": "#5 of 63 in its category",
   "note": "Dependency in 154 public GitHub projects set up for AI coding agents that we scanned (2.5%).",
   "src": null
  },
  {
   "key": "agent",
   "label": "Agent access",
   "value": "Install only",
   "status": "info",
   "sub": null,
   "note": "Agent skills for this library in the skills catalog; community skills are written by others, read them before you install.",
   "src": null
  }
 ],
 "vfoot": "From the package registry and GitHub, checked daily; card checked Nov 10, 2026.",
 "blocks": [
  {
   "id": "overview",
   "nav": "Overview",
   "h2": "What Ajv does",
   "parts": [
    {
     "t": "prose",
     "text": "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."
    },
    {
     "t": "h3",
     "text": "What people build with it"
    },
    {
     "t": "uses",
     "items": [
      {
       "title": "Check what reaches your server",
       "text": "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.",
       "idea": false
      },
      {
       "title": "Show every form mistake at once",
       "text": "A sign-up form lists all problems together, such as a bad email and a too-young age, instead of one at a time.",
       "idea": false
      },
      {
       "title": "Fill in defaults, drop extras",
       "text": "When a request leaves out the plan, it becomes \"free\"; fields you never asked for, like an admin flag, are removed before you save.",
       "idea": false
      },
      {
       "title": "Check JSON from an AI model",
       "text": "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.",
       "idea": true
      },
      {
       "title": "Strict pages without eval",
       "text": "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.",
       "idea": false
      },
      {
       "title": "Catch typos in settings files",
       "text": "Check a settings file people edit by hand when your tool starts, and name the line that is wrong instead of failing later.",
       "idea": true
      }
     ]
    }
   ]
  },
  {
   "id": "popularity",
   "nav": "Popularity",
   "h2": "Ajv popularity",
   "parts": [
    {
     "t": "stats",
     "items": [
      {
       "n": "78",
       "of": "/ 100",
       "l": "Gid Score, #141 overall"
      },
      {
       "n": "547M",
       "l": "downloads a week, npm"
      },
      {
       "n": "14.9K",
       "l": "GitHub stars"
      },
      {
       "n": "154",
       "l": "agent projects use it"
      }
     ]
    },
    {
     "t": "small",
     "text": "Gid Score measures public popularity and activity, not quality.",
     "link": "How the Gid Score is calculated",
     "path": "tools/top/"
    }
   ]
  },
  {
   "id": "usage",
   "nav": "How it is used",
   "h2": "How Ajv is used",
   "parts": [
    {
     "t": "list",
     "items": [
      "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%)."
     ]
    },
    {
     "t": "h3",
     "text": "By coding agent"
    },
    {
     "t": "rows",
     "rows": [
      {
       "l": "109 projects, 3.3%",
       "v": "Claude Code",
       "path": "agents/claude-code/"
      },
      {
       "l": "77 projects, 2.5%",
       "v": "GitHub Copilot",
       "path": "agents/github-copilot/"
      },
      {
       "l": "45 projects, 1.8%",
       "v": "Cursor",
       "path": "agents/cursor/"
      },
      {
       "l": "44 projects, 9.3%",
       "v": "Gemini CLI",
       "path": "agents/gemini-cli/"
      },
      {
       "l": "37 projects, 11.1%",
       "v": "OpenClaw",
       "path": "agents/openclaw/"
      },
      {
       "l": "22 projects, 4.7%",
       "v": "OpenAI Codex",
       "path": "agents/openai-codex/"
      },
      {
       "l": "20 projects, 14.3%",
       "v": "Kiro",
       "path": "agents/kiro/"
      },
      {
       "l": "16 projects, 4.7%",
       "v": "OpenCode",
       "path": "agents/opencode/"
      }
     ]
    },
    {
     "t": "h3",
     "text": "Often used with"
    },
    {
     "t": "rows",
     "rows": [
      {
       "l": "In 37.7% of its projects",
       "v": "ajv-formats",
       "path": "tools/ajv-formats/"
      },
      {
       "l": "In 31.8% of its projects",
       "v": "yaml",
       "path": "tools/yaml/"
      },
      {
       "l": "In 30.5% of its projects",
       "v": "Commander",
       "path": "tools/commander/"
      },
      {
       "l": "In 29.9% of its projects",
       "v": "ws",
       "path": "tools/ws/"
      },
      {
       "l": "In 28.6% of its projects",
       "v": "chalk",
       "path": "tools/chalk/"
      },
      {
       "l": "In 27.9% of its projects",
       "v": "Express",
       "path": "tools/express/"
      },
      {
       "l": "In 48.1% of its projects",
       "v": "Vitest",
       "path": "tools/vitest/"
      },
      {
       "l": "In 40.3% of its projects",
       "v": "tsx",
       "path": "tools/tsx/"
      }
     ]
    }
   ]
  },
  {
   "id": "profile",
   "nav": "Profile",
   "h2": "Ajv in practice",
   "parts": [
    {
     "t": "h3",
     "text": "Strengths"
    },
    {
     "t": "rows",
     "rows": [
      {
       "l": "Schemas become generated code",
       "v": "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."
      },
      {
       "l": "Maintainers cite benchmarks for speed",
       "v": "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."
      },
      {
       "l": "Pick JSON Schema or JTD",
       "v": "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."
      },
      {
       "l": "JTD parsers and serializers",
       "v": "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."
      }
     ]
    },
    {
     "t": "h3",
     "text": "Watch out for"
    },
    {
     "t": "rows",
     "rows": [
      {
       "l": "Compiling is the slow part",
       "v": "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."
      },
      {
       "l": "<code>errors</code> is overwritten on every call",
       "v": "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."
      },
      {
       "l": "No errors-returning method is coming",
       "v": "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."
      }
     ]
    },
    {
     "t": "h3",
     "text": "Compile a schema and validate an object"
    },
    {
     "t": "tabs",
     "label": "Example",
     "items": [
      {
       "tab": "Javascript",
       "code": "// or ESM/TypeScript import\nimport Ajv from \"ajv\"\n// Node.js require:\nconst Ajv = require(\"ajv\")\n\nconst ajv = new Ajv() // options can be passed, e.g. {allErrors: true}\n\nconst schema = {\n  type: \"object\",\n  properties: {\n    foo: {type: \"integer\"},\n    bar: {type: \"string\"},\n  },\n  required: [\"foo\"],\n  additionalProperties: false,\n}\n\nconst data = {\n  foo: 1,\n  bar: \"abc\",\n}\n\nconst validate = ajv.compile(schema)\nconst valid = validate(data)\nif (!valid) console.log(validate.errors)"
      }
     ]
    }
   ]
  },
  {
   "id": "more",
   "nav": null,
   "spy_as": "profile",
   "h2": "More about Ajv",
   "parts": [
    {
     "t": "more",
     "items": [
      {
       "title": "Funding",
       "path": "tools/funding/",
       "items": [
        "GitHub Sponsors: https://github.com/epoberezkin",
        "Tidelift: https://tidelift.com/funding/github/npm/ajv",
        "Open Collective: https://opencollective.com/ajv",
        "15 GitHub sponsors"
       ]
      },
      {
       "title": "Head to head",
       "items": [
        {
         "text": "Zod vs Ajv",
         "note": "used together in 79 projects",
         "path": "tools/compare/zod-vs-ajv/"
        }
       ]
      },
      {
       "title": "Packages around it",
       "items": [
        "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"
       ]
      },
      {
       "title": "More in Forms, validation and schemas",
       "path": "tools/forms-validation/",
       "items": [
        {
         "text": "React Hook Form",
         "path": "tools/react-hook-form/"
        },
        {
         "text": "Pydantic",
         "path": "tools/pydantic/"
        },
        {
         "text": "React Hook Form Resolvers",
         "path": "tools/hookform/"
        },
        {
         "text": "jsonschema",
         "path": "tools/jsonschema/"
        },
        {
         "text": "ajv-formats",
         "path": "tools/ajv-formats/"
        },
        {
         "text": "zod-to-json-schema",
         "path": "tools/zod-to-json-schema/"
        },
        {
         "text": "Protocol Buffers",
         "path": "tools/protobuf/"
        },
        {
         "text": "email-validator",
         "path": "tools/email-validator/"
        }
       ]
      }
     ]
    }
   ]
  },
  {
   "id": "alternatives",
   "nav": "Alternatives",
   "h2": "Alternatives",
   "parts": [
    {
     "t": "alts",
     "items": [
      {
       "name": "Ajv",
       "me": true,
       "facts": [
        "MIT",
        "Gid 78",
        "547M/wk"
       ]
      },
      {
       "name": "Zod",
       "why": "Pick Zod when you write TypeScript and want to declare the rules in code and get matching types, rather than keep JSON Schema files.",
       "path": "tools/zod/",
       "facts": [
        "MIT",
        "Gid 89",
        "471M/wk"
       ]
      },
      {
       "name": "jsonschema",
       "why": "Pick jsonschema when the same JSON Schema checks have to run in a Python app.",
       "path": "tools/jsonschema/",
       "facts": []
      },
      {
       "name": "Pydantic",
       "why": "Pick Pydantic when your app is Python and you want data models with checks built from type hints.",
       "path": "tools/pydantic/",
       "facts": []
      },
      {
       "name": "Valibot",
       "why": "Modular and type-safe schema validation library for structural data with minimal bundle size.",
       "path": "tools/valibot/",
       "facts": [
        "MIT",
        "Gid 68",
        "36M/wk"
       ]
      },
      {
       "name": "TypeBox",
       "why": "JSON Schema type builder with static type resolution for TypeScript validation.",
       "path": "tools/sinclair-typebox/",
       "facts": [
        "MIT",
        "Gid 58",
        "17M/wk"
       ]
      },
      {
       "name": "Yup",
       "why": "Simple schema validation library for JavaScript with chainable API and error handling.",
       "path": "tools/yup/",
       "facts": [
        "MIT",
        "Gid 69",
        "16.6M/wk"
       ]
      }
     ],
     "more": "Compare Ajv with another tool",
     "more_path": "tools/compare/"
    }
   ]
  },
  {
   "id": "start",
   "nav": "Get started",
   "h2": "Get started",
   "parts": [
    {
     "t": "prompt",
     "text": "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."
    },
    {
     "t": "steps",
     "items": [
      {
       "text": "Install version 8 into your project (the older draft-04 schemas need version 6).",
       "code": "npm install ajv",
       "src": "https://github.com/ajv-validator/ajv/blob/master/README.md"
      },
      {
       "text": "Compile a schema once, then call the returned function on each piece of data; read validate.errors when it returns false.",
       "code": "// or ESM/TypeScript import\nimport Ajv from \"ajv\"\n// Node.js require:\nconst Ajv = require(\"ajv\")\n\nconst ajv = new Ajv() // options can be passed, e.g. {allErrors: true}\n\nconst schema = {\n  type: \"object\",\n  properties: {\n    foo: {type: \"integer\"},\n    bar: {type: \"string\"},\n  },\n  required: [\"foo\"],\n  additionalProperties: false,\n}\n\nconst data = {\n  foo: 1,\n  bar: \"abc\",\n}\n\nconst validate = ajv.compile(schema)\nconst valid = validate(data)\nif (!valid) console.log(validate.errors)\n",
       "src": "https://ajv.js.org/guide/getting-started.html"
      },
      {
       "text": "Add ajv-formats if your schema uses formats such as email, date or uri.",
       "code": "npm install ajv-formats",
       "src": "https://ajv.js.org/guide/formats.html"
      }
     ]
    },
    {
     "t": "h3",
     "text": "Rules for your agent"
    },
    {
     "t": "rules",
     "label": "Paste into AGENTS.md or CLAUDE.md",
     "text": "## Ajv\n- 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`.\n- Copy the `validate.errors` array reference to another variable if you need it later. Every validation call overwrites it.\n- `properties` alone does not require any keys or an object type. Use `required` for keys and `type` for the type.\n- `additionalProperties: false` only considers `properties` and `patternProperties` in the same schema object. Properties declared inside `oneOf`/`anyOf` subschemas count as additional.\n- Add the `ajv-formats` plugin for `format` keywords. Add remote schemas with `addSchema` or compile them so `$ref` can resolve them.\n- Compiled JTD parsers return `undefined` instead of throwing. Check the return value and read the parser's `message` and `position` properties.\n- Do not put validated data into logged error messages. Take property names from the error's `params` object when you build your own messages.\n"
    },
    {
     "t": "h3",
     "text": "Mistakes to avoid"
    },
    {
     "t": "mistakes",
     "items": [
      {
       "dont": "new Ajv() for a schema that uses draft 2020-12 keywords like prefixItems",
       "fix": "const Ajv2020 = require(\"ajv/dist/2020\"); new Ajv2020()",
       "why": "The default class is for draft-07; in our run it threw \"strict mode: unknown keyword: prefixItems\", and Ajv2020 accepted the same schema."
      },
      {
       "dont": "{type: \"string\", format: \"email\"} with a bare new Ajv()",
       "fix": "const addFormats = require(\"ajv-formats\"); addFormats(ajv) before compiling",
       "why": "Formats moved out of Ajv in version 7; in our run compile threw unknown format \"email\"."
      },
      {
       "dont": "Reading err.dataPath from validate.errors (Ajv 6 code and old answers online)",
       "fix": "Read err.instancePath (for example \"/email\"); messages now say \"must\" instead of \"should\"",
       "why": "Ajv 8 renamed the error field, so old code silently gets undefined."
      },
      {
       "dont": "Calling ajv.compile(schema) inside every request handler",
       "fix": "Compile each schema once at startup and reuse the validate function",
       "why": "Compiling is the slow part; running a compiled check is fast."
      },
      {
       "dont": "Keeping a reference to validate.errors and reading it after the next validate() call",
       "fix": "Copy the errors array right away if you need it later",
       "why": "Each call overwrites the errors property."
      }
     ]
    }
   ]
  },
  {
   "id": "faq",
   "nav": "Questions",
   "h2": "Questions",
   "parts": [
    {
     "t": "faq",
     "items": [
      {
       "q": "Can I use Ajv in a paid, closed-source app?",
       "a": "Yes. It is MIT licensed; keep its copyright and license notice in copies you ship.",
       "evidence": {
        "url": "https://github.com/ajv-validator/ajv/blob/master/LICENSE",
        "quote": "The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software."
       }
      },
      {
       "q": "Does it work in the browser?",
       "a": "Yes, in browsers and in Node.js 18 and newer. Pages with a strict security policy should ship checks compiled ahead of time.",
       "evidence": {
        "url": "https://github.com/ajv-validator/ajv/blob/master/README.md",
        "quote": "supports browsers and Node.js 18.x - current"
       }
      },
      {
       "q": "Why does my schema with format \"email\" throw an error?",
       "a": "Formats are not built into Ajv 8. Add the ajv-formats plugin, or the schema fails to compile.",
       "evidence": {
        "url": "https://ajv.js.org/strict-mode.html",
        "quote": "By default unknown formats throw exception during schema compilation"
       }
      },
      {
       "q": "My old schemas use draft-04. Which version do I need?",
       "a": "Ajv 6. Version 8 supports draft-06 and newer.",
       "evidence": {
        "url": "https://ajv.js.org/guide/getting-started.html",
        "quote": "you need to install Ajv version 6"
       }
      },
      {
       "q": "Why does Ajv reject a schema with an extra keyword like \"placeholder\"?",
       "a": "Strict mode is on by default and stops on keywords it does not know. Declare them with addKeyword or turn strict mode off.",
       "evidence": {
        "url": "https://ajv.js.org/strict-mode.html",
        "quote": "By default Ajv fails schema compilation when unknown keywords are used."
       }
      }
     ]
    }
   ]
  }
 ],
 "glance": [
  [
   "Package",
   "npm ajv"
  ],
  [
   "Category",
   "Forms, validation and schemas"
  ],
  [
   "License",
   "MIT"
  ],
  [
   "Latest version",
   "v8.20.0, April 24, 2026"
  ],
  [
   "On GitHub since",
   "May 2015"
  ],
  [
   "Gid Score",
   "77.6"
  ],
  [
   "Rank in category",
   "#5 of 63"
  ],
  [
   "GitHub",
   "ajv-validator/ajv"
  ],
  [
   "Last change",
   "Sep 6, 2026"
  ]
 ],
 "good": [
  "Ajv treats a schema like your own program code. Do not run schemas that strangers send you without limits on size and depth.",
  "Some rules, like text patterns on very long strings, can make a check slow. Add length limits and keep the \"all errors\" mode out of live servers.",
  "In a web page with a strict security policy, Ajv's on-the-fly checks need 'unsafe-eval'; checks compiled ahead of time avoid that."
 ],
 "checked_line": "Read by AgentGid from 17 official pages, card checked Nov 10, 2026; numbers update daily.",
 "logo": "https://agentgid.com/media/avatars/ajv-validator.png"
}