Home

joi

Joi is a JavaScript validation library used to describe and validate data through schemas. It provides a descriptive, chainable API for defining the shape and constraints of objects, arrays, and primitive values. Joi schemas are commonly used to enforce the structure of API inputs, configuration objects, and other data exchanged between a client and server.

Origin and scope: Joi was developed as part of the Hapijs project and is distributed as a

Core features: Joi supports schemas for strings, numbers, booleans, dates, arrays, and objects, with a wide range

Usage example: const Joi = require('joi'); const schema = Joi.object({ name: Joi.string().min(3).max(30).required(), age: Joi.number().integer().min(0).optional() }); const { value, error

Notes: Joi is one of several options for runtime validation in JavaScript; it emphasizes developer-friendly error

standalone
npm
package.
It
is
framework-agnostic
and
can
be
used
with
Express,
Fastify,
Koa,
or
in
any
Node.js
code
that
requires
runtime
validation
and
type
coercion.
of
validation
rules
(min,
max,
length,
pattern,
email,
etc.).
It
offers
required
and
optional
fields,
default
values,
and
custom
validation
via
.custom
or
.external.
Conditional
validation
can
be
expressed
with
when/alternatives.
Validation
results
include
a
value
after
coercion
and
a
detailed
error
object.
The
API
is
chainable,
readable,
and
designed
for
use
in
request
validation
pipelines.
}
=
schema.validate({
name:
'Ada',
age:
29
});
if
(error)
{
/*
handle
errors
*/
}
reporting
and
flexible
schema
definitions,
at
the
cost
of
some
additional
boilerplate
compared
to
lighter-weight
validators.