JavaScript validation libraries

Updated Nov 2026

JavaScript validation libraries check that incoming data, such as a request body or a form submission, has the shape and values an app expects. These libraries let APIs and AI agents reject malformed input before it reaches application code, including the arguments a language model passes to a tool.

Popularity

Ajv has the most monthly downloads in this comparison, at 2.0B.

LibraryMonthly downloadsStarsLast releaseLicense
Ajv
2.0B
14.9KApr 2026MIT
Zod
1.8B
44.3KOct 2026MIT
Effect
271.4M
17.6KNov 2026MIT
validator.js
137.1M
23.7KApr 2026MIT
Joi
132.0M
21.2KNov 2026BSD-3-Clause
Valibot
126.5M
9.1KSep 2026MIT
class-validator
67.3M
11.9KFeb 2026MIT
TypeBox
65.2M
7.0KNov 2026MIT
Downloads: npm, last thirty days. Stars and releases: GitHub. Amber: no release in over a year.

Features compared

LibraryObject schemasAsync checksInput conversion
AjvBuilt-inBuilt-inBuilt-in
ZodBuilt-inBuilt-inBuilt-in
EffectBuilt-inBuilt-inBuilt-in
validator.jsUnsupportedUnsupportedBuilt-in
JoiBuilt-inBuilt-inBuilt-in
ValibotBuilt-inBuilt-inBuilt-in
class-validatorBuilt-inBuilt-inVia plugin
TypeBoxBuilt-inUnsupportedBuilt-in
Built-inVia pluginNot supported

Libraries and code examples

Ajv validates data against JSON Schema and JSON Type Definition schemas in Node.js and browsers. ajv.compile turns a schema into a validation function and caches it, so the same schema object is never compiled twice. The function returns true or false and stores any problems in its errors property, with an option to collect every error instead of stopping at the first. Options can also remove extra properties, fill in default values, and coerce values to the types a schema declares. Formats such as email and date come from a separate plugin, ajv-formats.

Downloads / mo
2.0B
Stars
14.9K
Last release
8.20.0
License
MIT

Strengths

  • Reuses compiled schema validators. Compiles a schema once and reuses its validation function.
  • Supports asynchronous custom checks. Async formats and keywords handle checks that call a database or another service.

Limitations

  • Coercion changes object properties. With coercion on, Ajv changes properties of the validated object in place.
  • Standard formats need a plugin. Formats such as email and date come from the ajv-formats plugin.

Quickstart

From getting-started.md
$ npm install ajv@8.20.0
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 validate = ajv.compile(schema)

const data = {
  foo: 1,
  bar: "abc"
}

const valid = validate(data)
if (!valid) console.log(validate.errors)

Ajv examples

From open-source projects on GitHub

Zod is a TypeScript-first validation library with no external dependencies. A schema such as z.object describes the data, and .parse checks an input against it and returns a typed deep copy when the input is valid. The TypeScript type comes from the same schema, so the type and the runtime check can't drift apart. Refinements add custom checks, .parseAsync runs asynchronous ones, and z.toJSONSchema exports a schema to JSON Schema. For hot paths, z.compile builds a faster version of a schema ahead of time.

Downloads / mo
1.8B
Stars
44.3K
Last release
4.6.7
License
MIT

Strengths

  • Adds custom validation rules. Refinements add checks the built-in schema methods don't cover.
  • Converts schemas to JSON Schema. z.toJSONSchema exports a schema to JSON Schema.

Limitations

  • Async refinements need async parsing. A schema with async refinements needs parseAsync, or Zod throws.
  • Some types don't convert. Types with no JSON Schema equivalent can't be represented.

Quickstart

From README.md
$ npm install zod@4.6.7
import * as z from "zod";

const Player = z.object({
  username: z.string(),
  xp: z.number(),
});

Player.parse({ username: "billie", xp: 100 });
// => returns { username: "billie", xp: 100 }

Zod examples

From open-source projects on GitHub

Effect is a TypeScript standard library, and its Schema module defines schemas that validate and transform data. A schema describes two types: the encoded form that arrives as input and the type the app works with. Schema.decodeUnknownSync turns unknown input into the app's type or throws, and encoding converts a value back for output. The same schema can also produce a JSON Schema, test data generators, and equality checks. Decoders that return an Effect connect to the rest of the Effect library, such as its error handling and concurrency.

Downloads / mo
271.4M
Stars
17.6K
Last release
4.1.4
License
MIT

Strengths

  • Decodes and encodes. One schema turns input into the app's type and converts it back for output.

Limitations

  • Needs strict TypeScript. The strict flag has to be on in tsconfig.json.

Quickstart

From Schema.d.ts
$ npm install effect@4.1.4
import { Schema } from 'effect';

const User = Schema.Struct({
  name: Schema.String,
});

console.log(Schema.decodeUnknownSync(User)({ name: 'Ada' }));

Effect examples

From open-source projects on GitHub

validator.js is a library of string validators and sanitizers, with functions such as isEmail, isURL, and isMobilePhone. Each validator takes a string and returns true or false, and sanitizers such as escape and trim return a cleaned string. The library checks strings only, so other input has to be converted to a string first. Single functions can be imported on their own, and a standalone script runs in the browser.

Downloads / mo
137.1M
Stars
23.7K
Last release
13.15.35
License
MIT

Limitations

  • Strings only. Passing a number or an object throws an error, so convert input to a string first.

Quickstart

From README.md
$ npm install validator@13.15.35
var validator = require('validator');

validator.isEmail('foo@bar.com'); //=> true

validator.js examples

From open-source projects on GitHub
function mobile(value, options, field) {
  const normalizedOptions = options && typeof options === 'function' ? options(field) : options
  const locales = normalizedOptions?.locale || 'any'

  if (!helpers.isMobilePhone(value as string, locales, normalizedOptions)) {
    field.report(messages.mobile, 'mobile', field)
  }
}

Joi describes objects with a chained schema language, such as Joi.object with Joi.string and Joi.number fields, in plain JavaScript. schema.validate returns an object with the validated value and any error, and validateAsync handles rules that need to wait on other work. Values convert to the declared types by default, so a numeric string passes as a number. Rules can also reference other fields, which covers checks such as a password confirmation.

Downloads / mo
132.0M
Stars
21.2K
Last release
18.3.2
License
BSD-3-Clause

Strengths

  • Converts input values by default. Strings and other inputs convert to the required types unless convert is false.
  • Supports synchronous and async validation. validate runs synchronously, and validateAsync supports async rules.

Limitations

  • Custom rules run synchronously. Rules written with any.custom can't be asynchronous.

Quickstart

From API.md
$ npm install joi@18.3.2
const Joi = require('joi');

const schema = Joi.object({
    a: Joi.string(),
});

const { error, value } = schema.validate({ a: 'a string' });

Joi examples

From open-source projects on GitHub

Valibot validates data with schemas built from small, separate functions. A schema such as v.object lists the fields, v.pipe chains checks like v.email or v.minLength onto a type, and v.parse validates input or throws. Because each function is imported on its own, a bundler keeps only the checks a schema uses. Static types come from v.InferOutput, and the library has no dependencies and runs in any JavaScript environment.

Downloads / mo
126.5M
Stars
9.1K
Last release
1.5.0
License
MIT

Strengths

  • Small bundles. Each check is its own function, so a bundler keeps only the ones a schema uses.
  • No dependencies. Runs in any JavaScript environment, from servers to browsers.

Quickstart

From README.md
$ npm install valibot@1.5.0
import * as v from 'valibot';

const LoginSchema = v.object({
  email: v.pipe(v.string(), v.email()),
  password: v.pipe(v.string(), v.minLength(8)),
});

const output2 = v.parse(LoginSchema, {
  email: 'jane@example.com',
  password: '12345678',
});

Valibot examples

From open-source projects on GitHub

class-validator

class-validator checks objects through decorators placed on class properties, such as @IsEmail, @Length, and @Min. validate runs every rule on an instance and returns a list of errors, and validateOrReject throws instead. The checks themselves come from validator.js. Validation groups, nested objects, and custom decorators are supported, and rules can also be defined without decorators. Plain objects, such as parsed JSON, have to be turned into class instances first.

Downloads / mo
67.3M
Stars
11.9K
Last release
0.15.1
License
MIT

Strengths

  • Rules as decorators. Decorators such as IsEmail run validator.js checks on class properties.

Limitations

  • Class instances only. Plain objects have to become class instances first, for example with class-transformer.

Quickstart

From README.md
$ npm install class-validator@0.15.1
import { IsEmail, validate } from 'class-validator';

class EmailInput {
  @IsEmail()
  email = 'jane@example.com';
}

console.log(await validate(new EmailInput()));

class-validator examples

From open-source projects on GitHub

TypeBox builds JSON Schema objects in TypeScript with functions such as Type.Object and Type.Number, and Type.Static reads the matching TypeScript type from each one. The result is one definition that TypeScript checks at compile time and any JSON Schema validator checks at runtime. TypeBox also includes its own compiler and value functions, so validation can run without a separate library. Services that already exchange JSON Schema, such as REST and RPC APIs, can use the schemas as they are.

Downloads / mo
65.2M
Stars
7.0K
Last release
1.4.7
License
MIT

Strengths

  • One definition, two uses. The same object is a TypeScript type at compile time and a JSON Schema at runtime.

Quickstart

From readme.md
$ npm install typebox@1.4.7
import Type from 'typebox'

import Schema from 'typebox/schema'

// Compile

const Vector = Schema.Compile(Type.Script(`{
  x: number
  y: number
  z: number
}`))

// Check

const valid = Vector.Check({ x: 1, y: 0, z: 0 })   // const valid: boolean

TypeBox examples

From open-source projects on GitHub

FAQ

In TypeScript, Zod defines a schema once and infers its type, and Valibot does the same with separately imported functions that keep bundles small. For data described in JSON Schema, use Ajv. For rules written as decorators on classes, use class-validator, and for single strings such as email addresses, validator.js.

Yup casts input into the declared types and can transform it before validating. Zod parses input and returns a typed deep copy when it is valid, and it infers the TypeScript type from the schema.

Joi validates objects in plain JavaScript and converts values, such as a numeric string to a number, by default. Zod is TypeScript first: one schema gives both the runtime check and the static type.

Both define schemas in TypeScript and infer static types. Valibot splits its API into separate functions, such as v.pipe and v.email, so a bundler keeps only the ones in use, and its bundle starts under one kilobyte. Zod chains methods on a schema object.

Ajv validates data against JSON Schema documents and compiles each schema into a reusable function. Zod defines schemas in TypeScript and infers types from them. When another tool needs JSON Schema, z.toJSONSchema exports a Zod schema to that format.

For coding agents

Found your validation library? Help your agent use it.

Connect Exa so your coding agent can find the library’s documentation, check its API, and look up implementations while you build.

Run in your terminal

claude plugin install exa@claude-plugins-official