express-validator vs is-my-json-valid vs joi vs validator
Input Validation Strategies for Node.js and Full-Stack Apps
express-validatoris-my-json-validjoivalidatorSimilar Packages:

Input Validation Strategies for Node.js and Full-Stack Apps

express-validator, is-my-json-valid, joi, and validator are libraries used to check and clean data in JavaScript applications. validator is a low-level tool for checking single strings like emails or URLs. express-validator builds on validator to add middleware features for Express servers. joi allows developers to define complex object schemas with rules for nested data. is-my-json-valid focuses on validating data against the official JSON Schema standard. Together, they cover everything from simple string checks to full API request validation.

Npm Package Weekly Downloads Trend

3 Years

Github Stars Ranking

Stat Detail

Package
Downloads
Stars
Size
Issues
Publish
License
express-validator06,246146 kB77a day agoMIT
is-my-json-valid096640.2 kB554 years agoMIT
joi021,202585 kB1883 days agoBSD-3-Clause
validator023,755824 kB373an hour agoMIT

Validation Libraries: express-validator, is-my-json-valid, joi, validator

When building full-stack applications, checking user input is critical for security and data integrity. The four libraries — express-validator, is-my-json-valid, joi, and validator — all solve this problem but take very different approaches. Some focus on single strings, others on complex objects, and some on specific standards like JSON Schema. Let's look at how they handle real-world tasks.

🏗️ Core Philosophy: Strings vs Schemas vs Middleware

The biggest difference lies in what each tool expects as input and where it fits in your code.

validator is a collection of pure functions. It does not store state or know about your app structure. You pass a string and get a true or false result.

express-validator is a set of middleware for Express. It knows about the HTTP request object and collects errors from multiple fields automatically.

joi is a schema builder. You define the shape of your data once and reuse it anywhere — in an API route, a config file, or a browser form.

is-my-json-valid is a compiler for JSON Schema. It takes a standard JSON Schema object and returns a function that validates data against that standard.

✍️ Defining Validation Rules

How you write rules changes heavily between these tools. validator uses function calls, while joi and is-my-json-valid use object definitions.

validator requires you to call specific functions for each check. There is no central schema object.

import validator from 'validator';

// Check email format directly
const isValid = validator.isEmail('test@example.com');

// Check age range manually
const age = 20;
const isAdult = age >= 18 && age <= 99;

express-validator uses a chainable API within your route definition. You declare checks alongside your handler.

import { body } from 'express-validator';

// Define rules in the route array
app.post('/user', [
  body('email').isEmail(),
  body('age').isInt({ min: 18, max: 99 })
], (req, res) => {
  // Handler logic
});

joi uses a fluent interface to build a schema object. This schema can be saved and reused.

import Joi from 'joi';

// Define a reusable schema
const userSchema = Joi.object({
  email: Joi.string().email().required(),
  age: Joi.number().integer().min(18).max(99).required()
});

is-my-json-valid uses the standard JSON Schema format. This is a plain JSON object describing the data structure.

import validator from 'is-my-json-valid';

// Define standard JSON Schema
const schema = {
  type: 'object',
  properties: {
    email: { type: 'string', format: 'email' },
    age: { type: 'integer', minimum: 18, maximum: 99 }
  },
  required: ['email', 'age']
};

⚡ Running Validation

Once rules are defined, the execution step varies. Some tools validate immediately, while others wait for an HTTP request.

validator runs immediately when you call the function. It returns a boolean.

import validator from 'validator';

const input = 'not-an-email';
if (!validator.isEmail(input)) {
  console.log('Invalid email');
}

express-validator runs automatically when the request hits the route. You retrieve results inside the handler.

import { validationResult } from 'express-validator';

app.post('/user', [
  body('email').isEmail()
], (req, res) => {
  const errors = validationResult(req);
  if (!errors.isEmpty()) {
    return res.status(400).json({ errors: errors.array() });
  }
});

joi requires you to call the validate or validateAsync method on your schema.

import Joi from 'joi';

const { error, value } = userSchema.validate({
  email: 'test@example.com',
  age: 25
});

if (error) {
  console.log(error.message);
}

is-my-json-valid compiles the schema into a validate function first. Then you pass data to that function.

import validator from 'is-my-json-valid';

const validate = validator(schema);
const valid = validate({ email: 'test@example.com', age: 25 });

if (!valid) {
  console.log(validate.errors);
}

🚨 Error Handling & Output

When validation fails, the shape of the error message matters for debugging and user feedback.

validator gives no error details by default. You only get false. You must write your own error messages.

// validator
if (!validator.isEmail(input)) {
  // You must create this string yourself
  throw new Error('Email format is incorrect');
}

express-validator collects all errors from the request into a structured array. It includes the field name and value.

// express-validator
const errors = validationResult(req);
// Returns: [{ msg: 'Invalid value', param: 'email', location: 'body' }]

joi provides very detailed error messages out of the box. It explains exactly why a field failed.

// joi
// Error message: '"age" must be greater than or equal to 18'
console.log(error.details[0].message);

is-my-json-valid returns errors based on JSON Schema keywords. It tells you which keyword failed (e.g., minimum, format).

// is-my-json-valid
// Returns: [{ field: 'data.age', message: 'must be minimum 18' }]
console.log(validate.errors);

🌍 Environment & Integration

Where you can run these tools affects your architecture. Some are server-only, while others work in the browser.

validator is isomorphic. It works in Node.js and the browser. This allows you to share simple checks between client and server.

express-validator is server-only. It depends on the Express request and response objects. You cannot use it in frontend code.

joi works in both Node.js and the browser. This makes it great for sharing schema logic in full-stack frameworks like Next.js or Remix.

is-my-json-valid is primarily designed for Node.js. While it is JavaScript, it is typically used in backend services or build tools where JSON Schema is enforced.

📊 Summary Table

Featurevalidatorexpress-validatorjoiis-my-json-valid
Input TypeSingle StringExpress RequestObject / AnyObject (JSON Schema)
Schema StyleNone (Functions)Middleware ChainFluent BuilderJSON Schema Standard
Error MessagesNone (Boolean)Structured ArrayDetailed & ReadableKeyword Based
EnvironmentBrowser & ServerServer (Express)Browser & ServerServer (Node)
Best ForSimple ChecksExpress APIsComplex ObjectsStandard Compliance

💡 Final Recommendation

Selecting the right tool depends on your project structure and validation needs.

validator is best for lightweight, isolated checks. Use it when you need to verify a single email or URL in a utility function without pulling in a heavy library.

express-validator is the standard choice for Express APIs. If you are building a traditional backend, it reduces boilerplate and keeps validation close to your routes.

joi is the top pick for complex data structures. If you need to validate nested objects or share validation logic between frontend and backend, its schema system is powerful and flexible.

is-my-json-valid is niche but useful for standards. Choose it if you must adhere to JSON Schema for interoperability with other tools or services.

For most modern full-stack teams, joi offers the best balance of power and flexibility. However, if you are already deep in the Express ecosystem, express-validator provides the smoothest integration.

How to Choose: express-validator vs is-my-json-valid vs joi vs validator

  • express-validator:

    Choose express-validator if you are building an Express.js API and want validation tied directly to your route handlers. It simplifies error handling by collecting issues from multiple fields into one result object. This is the best fit for traditional Node.js backend services where request middleware is standard.

  • is-my-json-valid:

    Choose is-my-json-valid if your project requires strict compliance with the JSON Schema specification. It is ideal when you need to share validation rules with other systems that also use JSON Schema. However, for general Node.js apps, other tools may offer better developer experience.

  • joi:

    Choose joi if you need to validate complex nested objects or want a powerful schema builder that works outside of Express. It is excellent for shared validation logic between server and client or for validating configuration files. The detailed error messages make it strong for user-facing forms.

  • validator:

    Choose validator if you only need to check simple strings like emails, URLs, or credit card numbers without defining a full schema. It is lightweight and works in both browser and server environments. Use this when you need a quick check without the overhead of a larger library.

README for express-validator

express-validator

npm version Build status Coverage Status

An express.js middleware for validator.

Installation

npm install express-validator

Also make sure that you have Node.js 14 or newer in order to use it.

Documentation

Please refer to the documentation website on https://express-validator.github.io.

Changelog

Check the GitHub Releases page.

License

MIT License