API Reference

Joi

Powerful schema description language and data validator for JavaScript with rich rules and custom errors.

Official Documentation ↗
CompatibilityThis documentation covers version v17.13. Check the official docs for the latest API surface.

Installation

npmnpm install joi
pnpmpnpm add joi
yarnyarn add joi

Methods

Joi is a schema description language and data validator for JavaScript. It lets you create blueprints for JavaScript objects to ensure validation of configuration, inputs, and API payloads with a rich rule set.

Key Features

  • Rich rules: String, number, date, array, object, alternatives, binary
  • Custom types: Extend Joi with domain-specific validators
  • Detailed errors: Error details with path, type, and context
  • References: Cross-field validation with Joi.ref()
  • Preferences: Global options for abortEarly, stripUnknown, convert

Errors

The following points are quoted verbatim from the official documentation (https://joi.dev/). Any error type, throw condition or recovery step not stated there is left unspecified; this page does not infer exception classes or return values.

  • Rich, Actionable Errors ​ Every validation failure includes the exact path, a machine-readable type code, the failing value, and the constraint that was violated. (https://joi.dev/)

FAQ

Is Joi still maintained?
Joi is maintained under the hapi ecosystem. New projects often choose Zod or Yup for TypeScript inference, but Joi remains stable, battle-tested, and excellent for config and API validation.
How do I customize error messages?
Pass a messages object to .messages() or per-rule via .message(). You can also use .label() to rename fields and .prefs({ messages }) for global overrides with context placeholders.
Can Joi strip unknown keys?
Yes. Set stripUnknown: true in validate options or schema preferences. Without it, unknown keys are allowed by default unless you set schema.unknown(false).