Why is JOI more popular than AJV? Why is JOI more popular than AJV? javascript javascript

Why is JOI more popular than AJV?


The important difference between AJV and Joi is that AJV is a JSON Schema validator and Joi is a JavaScript validator. JSON Schema is cross-platform while Joi only works in JavaScript. So, this isn't a choice between AJV and Joi as much as it's a choice between JSON Schema and Joi.

Each approach has its trade-offs, so which you choose depends a lot on your specific situation.

AJV/JSON Schema

The big win you get from JSON Schema is that it's cross platform. JSON Schema validator implementations exist in every major programming language. No matter what language you choose, you can use the same JSON Schema on the frontend and the backend and get consistent validation results. Write once, validate anywhere.

The downside is that because it's cross platform, it's also somewhat limited in what it can do. It's purposely kept simple enough so that it's not too difficult to implement in any programming language. Because JSON Schema isn't a full fledged programming language, it's limited in what it can do.

You might choose AJV/JSON Schema if you are using something other than JavaScript on the backend or your app is a public API that could be used by any number of apps in any number of languages.

Joi

Joi's biggest advantage is its usability. It's easy to use, easy to extend, and it has the full power of JavaScript.

The downside is that if you want to reuse your validation logic on the frontend and the backend, your only choice of language on the backend is node.

You might choose Joi if you use JavaScript for the frontend and the backend and don't anticipate non-JavaScript clients that you need to support. This is a fairly narrow situation, but if it is your situation, you will likely get more out or Joi than AJV/JSON Schema.

Popularity

Github stars aren't a great measure of popularity. If you look at npm daily downloads you see a very different story (AJV: 18.9M, Joi: 2.2M). JSON Schema is by far more widely used because it is cross platform. AJV is just one implementation in one language. But, if your development stack fits Joi's particular niche, it can be just as good a choice or a better choice than JSON Schema.