Use this file to discover Exa products, pricing, evaluations, comparisons, use cases, agent interfaces, and technical documentation before exploring further.
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.
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.
function validateObject(schema, options) {
// Not need to cache, because `ajv@8` has built-in cache const compiledSchema = getAjv().compile(schema);
const valid = compiledSchema(options);
if (valid) return [];
return compiledSchema.errors ? filterErrors(compiledSchema.errors) : [];
}
Zod
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.
export function zodResolver<Input extends FieldValues, Context, Output>(
schema: object,
schemaOptions?: object,
resolverOptions: {
mode?: 'async' | 'sync';
raw?: boolean;
} = {},
): Resolver<Input, Context, Output | Input> {
// Zod 4 is checked first: its `_zod` marker is unambiguous, whereas the // Zod 3 check below only requires an object-shaped `_def` (to support // dynamically-selected schemas typed via the generic `z.ZodType<Output>` // annotation, see `isZod3Schema`) — and Zod 4 schemas also have an // object-shaped `_def`, so they'd otherwise be misdetected as Zod 3. if (isZod4Schema(schema)) {
return async (values: Input, _, options) => {
try {
// Call the schema's own bound `parse`/`parseAsync` method rather // than the standalone `z4.parse`/`z4.parseAsync` functions. Those // standalone functions read from this module's own imported // `zod/v4/core`, which — under bundlers that can resolve `zod` and // `zod/v4/core` to two distinct module instances (e.g. Metro with // package-exports resolution enabled) — may not be the same zod // instance the schema was created with, silently dropping any // global config (`z.config()`) or locale the app configured on its // own zod instance. The schema's own method is always bound to // whichever zod instance actually created it. const classicSchema = schema as unknown as {
parse: (values: unknown, schemaOptions: unknown) => unknown;
parseAsync: (
values: unknown,
schemaOptions: unknown,
) => Promise<unknown>;
};
const data: any =
resolverOptions.mode === 'sync'
? classicSchema.parse(values, schemaOptions)
: await classicSchema.parseAsync(values, schemaOptions);
options.shouldUseNativeValidation &&
validateFieldsNatively({}, options);
return {
errors: {},
values: resolverOptions.raw ? Object.assign({}, values) : data,
} satisfies ResolverSuccess<Output | Input>;
} catch (error) {
if (isZod4Error(error)) {
return {
values: {},
errors: toNestErrors(
parseZod4Issues(
error.issues,
!options.shouldUseNativeValidation &&
options.criteriaMode === 'all',
),
options,
),
} satisfies ResolverError<Input>;
}
throw error;
}
};
}
if (isZod3Schema(schema)) {
return async (values: Input, _, options) => {
try {
const data = await schema[
resolverOptions.mode === 'sync' ? 'parse' : 'parseAsync'
](values, schemaOptions);
options.shouldUseNativeValidation &&
validateFieldsNatively({}, options);
return {
errors: {},
values: resolverOptions.raw ? Object.assign({}, values) : data,
} satisfies ResolverSuccess<Output | Input>;
} catch (error) {
if (isZod3Error(error)) {
return {
values: {},
errors: toNestErrors(
parseZod3Issues(
error.errors,
!options.shouldUseNativeValidation &&
options.criteriaMode === 'all',
),
options,
),
} satisfies ResolverError<Input>;
}
throw error;
}
};
}
throw new Error('Invalid input: not a Zod schema');
}
Effect
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.
export function effectTsResolver<Input extends FieldValues, Context, Output>(
schema: Schema.Codec<Output, Input, never, unknown>,
schemaOptions: ParseOptions = { errors: 'all', onExcessProperty: 'ignore' },
resolverOptions: { raw?: boolean } = {},
): Resolver<Input, Context, Output | Input> {
return (values, _, options) =>
Schema.decodeUnknownEffect(schema)(values, schemaOptions).pipe(
Effect.match({
onFailure: ({ issue }) => {
const validateAllFieldCriteria =
!options.shouldUseNativeValidation &&
options.criteriaMode === 'all';
// A null-prototype accumulator avoids false-positive hits from // inherited members (e.g. `toString`, `constructor`) when a field // is named after one of them — a plain `{}` would make `!acc[key]` // truthy-skip those paths and silently drop their errors. const errors = flattenIssue(issue, []).reduce(
(acc, error) => {
const key = error.path.join('.');
if (!acc[key]) {
acc[key] = { message: error.message, type: error.type };
}
if (validateAllFieldCriteria) {
const types = acc[key].types;
const messages = types && types[error.type];
acc[key] = appendErrors(
key,
validateAllFieldCriteria,
acc,
error.type,
messages
? ([] as string[]).concat(
messages as string[],
error.message,
)
: error.message,
) as FieldError;
}
return acc;
},
Object.create(null) as Record<string, FieldError>,
);
return { errors: toNestErrors(errors, options), values: {} };
},
onSuccess: (result) => {
options.shouldUseNativeValidation &&
validateFieldsNatively({}, options);
return {
errors: {},
values: resolverOptions.raw ? Object.assign({}, values) : result,
};
},
}),
Effect.runPromise,
);
}
validator.js
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.
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.
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.
export function valibotResolver<Input extends FieldValues, Context, Output>(
schema: BaseSchema<Input, Output, any> | BaseSchemaAsync<Input, Output, any>,
schemaOptions?: Partial<
Omit<Config<InferIssue<typeof schema>>, 'abortPipeEarly' | 'skipPipe'>
>,
resolverOptions: {
/**
* @default async
*/
mode?: 'sync' | 'async';
/**
* Return the raw input values rather than the parsed values.
* @default false
*/
raw?: boolean;
} = {},
): Resolver<Input, Context, Output | Input> {
return async (values: Input, _, options) => {
// Check if we should validate all field criteria const validateAllFieldCriteria =
!options.shouldUseNativeValidation && options.criteriaMode === 'all';
// Parse values with Valibot schema const result = await safeParseAsync(
schema,
values,
Object.assign({}, schemaOptions, {
abortPipeEarly: !validateAllFieldCriteria,
}),
);
// If there are issues, return them as errors if (result.issues) {
// Create errors object. A null-prototype object avoids false-positive // hits from inherited members (e.g. `toString`, `constructor`) when a // field is named after one of them — a plain `{}` would make // `!errors[path]` truthy-skip those paths and silently drop their // errors. const errors: Record<string, FieldError> = Object.create(null);
// Iterate over issues to add them to errors object for (; result.issues.length; ) {
const issue = result.issues[0];
// Object-level checks report no dot path; keep them on the empty key const path = getDotPath(issue) ?? '';
// Add first error of path to errors object if (!errors[path]) {
errors[path] = { message: issue.message, type: issue.type };
}
// If configured, add all errors of path to errors object if (validateAllFieldCriteria) {
const types = errors[path].types;
const messages = types && types[issue.type];
errors[path] = appendErrors(
path,
validateAllFieldCriteria,
errors,
issue.type,
messages
? ([] as string[]).concat(
messages as string | string[],
issue.message,
)
: issue.message,
) as FieldError;
}
result.issues.shift();
}
// Return resolver result with errors return {
values: {},
errors: toNestErrors(errors, options),
} as const;
}
options.shouldUseNativeValidation && validateFieldsNatively({}, options);
// Otherwise, return resolver result with values return {
values: resolverOptions.raw ? Object.assign({}, values) : result.output,
errors: {},
};
};
}
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.
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.
({ schema, httpPart }) => {
const typeCheck = Compile(schema)
return (value): any /* TODO: remove any for next major */ => {
// Note: Only support value conversion for querystring, params and header schematics const converted = httpPart === 'body' ? value : Value.Convert(schema, value)
if (typeCheck.Check(converted)) {
return { value: converted }
}
const errors: FastifySchemaValidationError[] = typeCheck.Errors(converted)
return {
error: errors
}
}
}
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.