ajv, is-my-json-valid, joi, and jsonschema are libraries used to validate data structures in JavaScript applications, but they approach the problem differently. ajv, is-my-json-valid, and jsonschema validate against the JSON Schema standard, using plain objects to define rules. joi uses a chainable JavaScript API to build schemas, offering a more programmatic experience. These tools help ensure data integrity at API boundaries, form inputs, and configuration files.
Validating data is a core part of building reliable software. Whether you are checking API responses, form inputs, or configuration files, you need to ensure the data matches your expectations. The packages ajv, is-my-json-valid, joi, and jsonschema all solve this problem, but they use different methods and standards. Let's look at how they compare in real-world engineering scenarios.
The way you define validation rules differs significantly between these libraries. Three of them use the JSON Schema standard, while one uses a custom builder pattern.
ajv uses standard JSON Schema objects.
// ajv: JSON Schema object
const schema = {
type: "object",
properties: {
name: { type: "string" },
age: { type: "integer", minimum: 0 }
},
required: ["name"]
};
is-my-json-valid also uses standard JSON Schema objects.
ajv but lacks support for newer drafts.// is-my-json-valid: JSON Schema object
const schema = {
type: "object",
properties: {
name: { type: "string" },
age: { type: "number", minimum: 0 }
},
required: ["name"]
};
jsonschema relies on standard JSON Schema objects as well.
// jsonschema: JSON Schema object
const schema = {
type: "object",
properties: {
name: { type: "string" },
age: { type: "integer", minimum: 0 }
},
required: ["name"]
};
joi uses a chainable JavaScript API.
.object(), .string(), and .required().// joi: Chainable builder
const schema = Joi.object({
name: Joi.string().required(),
age: Joi.number().integer().min(0)
});
Performance often depends on how the library processes the schema. Some compile the schema into code, while others interpret it at runtime.
ajv compiles schemas into fast validation functions.
compile() once, then use the returned function many times.// ajv: Compile once, validate many times
const ajv = new Ajv();
const validate = ajv.compile(schema);
const valid = validate(data);
is-my-json-valid also compiles schemas to code.
// is-my-json-valid: Compile to function
const validate = require('is-my-json-valid')(schema);
const valid = validate(data);
jsonschema interprets the schema at runtime.
// jsonschema: Direct validation
const validator = new Validator();
const result = validator.validate(data, schema);
const valid = result.valid;
joi compiles schemas internally.
.validate() on it.// joi: Validate against schema
const { error, value } = schema.validate(data);
const valid = !error;
When validation fails, you need clear error messages to fix the data. Each library handles error output differently.
ajv provides standard error objects.
// ajv: Error details
if (!validate(data)) {
console.log(validate.errors);
// [{ instancePath: "/age", keyword: "minimum" }]
}
is-my-json-valid returns simple error lists.
// is-my-json-valid: Error list
if (!validate(data)) {
console.log(validate.errors);
// [{ field: "data.age", message: "must be >= 0" }]
}
jsonschema returns a result object with errors.
// jsonschema: Result object
const result = validator.validate(data, schema);
if (!result.valid) {
console.log(result.errors);
// [{ property: "instance.age", message: "..." }]
}
joi offers highly readable error messages.
// joi: Readable error
const { error } = schema.validate(data);
if (error) {
console.log(error.message);
// "age" must be a positive integer
}
Choosing a library means trusting its maintainers. Some of these packages are actively developed, while others are legacy tools.
ajv is actively maintained.
is-my-json-valid is unmaintained.
ajv instead.jsonschema is maintained but slower.
joi is actively maintained.
| Feature | ajv | is-my-json-valid | jsonschema | joi |
|---|---|---|---|---|
| Schema Format | JSON Schema | JSON Schema | JSON Schema | Chainable JS |
| Execution | Compiled Code | Compiled Code | Interpreted | Compiled Internally |
| Performance | ⚡ Very Fast | ⚡ Fast | 🐢 Slower | ⚡ Fast |
| Maintenance | ✅ Active | ❌ Unmaintained | ✅ Active | ✅ Active |
| Best For | Standards + Speed | Legacy Support | Strict Compliance | Developer Experience |
ajv is the top choice for most teams 🏆. It combines speed, standard compliance, and active maintenance. Use it when you need to validate JSON Schema specifically.
joi is the best alternative for developer happiness 😊. If you don't need strict JSON Schema compatibility, its API is easier to write and read. It shines in Node.js APIs.
jsonschema has a niche role 🛠️. Use it if you cannot use code generation (e.g., strict CSP environments) and need JSON Schema support.
is-my-json-valid should be avoided 🚫. It is legacy software. If you find it in an old codebase, plan to replace it with ajv.
Final Thought: For modern frontend and Node.js development, stick with ajv for standards-based validation or joi for flexible schema building. Both will serve your architecture well without the risks of unmaintained code.
Choose ajv for high-performance validation where JSON Schema compliance is required. It is the industry standard for validating JSON Schema drafts v4 through v2020. Ideal for large-scale applications needing speed and strict standard adherence.
Avoid is-my-json-valid for new projects. It is unmaintained and lacks support for modern JSON Schema drafts. Existing projects using it should plan to migrate to ajv for security and compatibility updates.
Choose joi when developer experience and flexible schema definitions matter more than strict JSON Schema compliance. It is excellent for Node.js backends and APIs where custom validation logic is common.
Choose jsonschema if you need a pure JavaScript implementation of JSON Schema without code generation. It is suitable for environments where dynamic compilation is restricted, though it is slower than ajv.
The fastest JSON validator for Node.js and browser.
Supports JSON Schema draft-04/06/07/2019-09/2020-12 (draft-04 support requires ajv-draft-04 package) and JSON Type Definition RFC8927.
More than 100 people contributed to Ajv, and we would love to have you join the development. We welcome implementing new features that will benefit many users and ideas to improve our documentation.
Please review Contributing guidelines and Code components.
All documentation is available on the Ajv website.
Some useful site links:
Since I asked to support Ajv development 40 people and 6 organizations contributed via GitHub and OpenCollective - this support helped receiving the MOSS grant!
Your continuing support is very important - the funds will be used to develop and maintain Ajv once the next major version is released.
Please sponsor Ajv via:
Thank you.
Ajv generates code to turn JSON Schemas into super-fast validation functions that are efficient for v8 optimization.
Currently Ajv is the fastest and the most standard compliant validator according to these benchmarks:
Performance of different validators by json-schema-benchmark:
addSchema or compiled to be available)type keywordsTo install version 8:
npm install ajv
Try it in the Node.js REPL: https://runkit.com/npm/ajv
In JavaScript:
// 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)
Learn how to use Ajv and see more examples in the Guide: getting started
See https://github.com/ajv-validator/ajv/releases
Please note: Changes in version 8.0.0
Please review and follow the Code of conduct.
Please report any unacceptable behaviour to ajv.validator@gmail.com - it will be reviewed by the project team.
To report a security vulnerability, please use the Tidelift security contact. Tidelift will coordinate the fix and disclosure. Please do NOT report security vulnerabilities via GitHub issues.
Ajv is a part of Tidelift subscription - it provides a centralised support to open-source software users, in addition to the support provided by software maintainers.