COMPARISON · VALIDATION

class-validator vs. joi

Side-by-side comparison · 9 metrics · 14 criteria

class-validator v0.15.1 · MIT
Weekly Downloads
18.0M
Stars
11.9K
Gzip Size
105.8 kB
License
MIT
Last Updated
9mo ago
Open Issues
329
Forks
848
Unpacked Size
5.3 MB
Dependencies
N/A
joi v18.3.2 · BSD-3-Clause
Weekly Downloads
33.6M
Stars
21.2K
Gzip Size
55.0 kB
License
BSD-3-Clause
Last Updated
1y ago
Open Issues
217
Forks
1.5K
Unpacked Size
1.9 MB
Dependencies
1
DOWNLOAD TRENDS

class-validator vs joi downloads · last 12 months

Download trends for class-validator and joi2 download series from Nov 2025 to Oct 2026. Use left and right arrow keys to inspect monthly values.032.5M65.0M97.5M130.0MNov 2025FebMayAugOct 2026
class-validator
joi
FEATURE COMPARISON

Criteria · class-validator vs joi

Schema Reuse
class-validator
Reusable rules are associated with decorated classes
joi ✓
Schemas can be handled as explicit validation values
Learning Curve
class-validator
Requires understanding decorators and instance validation
joi
Requires learning the schema-oriented API
Rule Placement
class-validator
Constraints sit on class properties
joi
Constraints live in schema declarations
Bundle Footprint
class-validator
Listed at 105.8 kB gzip
joi ✓
Listed at 55.0 kB gzip
Migration Effort
class-validator
Requires classes and decorated properties
joi
Requires schema definitions and schema-based calls
Validation Model
class-validator
Validates class instances using property decorators
joi
Validates objects against explicit schemas
Unpacked Footprint
class-validator
Listed at 5.3 MB unpacked
joi ✓
Listed at 1.9 MB unpacked
TypeScript Integration
class-validator ✓
Uses TypeScript class properties and decorators
joi
Describes object validation through schemas
Constraint Organization
class-validator
Rules are colocated with declared properties
joi
Rules are grouped in object schemas
Data Representation Fit
class-validator
Best aligned with class instances
joi
Best aligned with object-shaped data
Plain Object Validation
class-validator
Requires a class-instance-oriented flow
joi ✓
Directly fits plain object inputs
Class-Oriented Codebases
class-validator ✓
Naturally aligns validation with class definitions
joi
Schema remains separate from class declarations
Operational Track Record
class-validator
16.9M weekly downloads and 329 open issues
joi ✓
33.9M weekly downloads and 210 open issues
Validation Boundary Clarity
class-validator
Validation is attached to class structure
joi ✓
Validation is visibly invoked with a schema
VERDICT

class-validator is designed for developers who model application data as TypeScript classes and want validation rules declared on class properties. Its decorator-based approach keeps constraints close to the fields they govern, which can suit class-oriented codebases where those classes already represent request or domain objects. It is less natural when the input is an arbitrary object and there is no class instance to validate.

joi is built around describing and validating object shapes with schemas. That makes it a direct fit for data arriving as plain objects, such as parsed request payloads or configuration values, without requiring the data to be expressed as decorated classes first. Its schema-first philosophy is particularly useful when validation needs to be explicit and separated from the shape’s runtime representation.

The central architectural difference is where the rules live and how data reaches them. With class-validator, a developer adds decorators to class properties and validates an instance against that metadata; with joi, a developer defines a schema and passes an object through schema validation. The choice affects design: class-validator ties validation to class definitions, while joi makes the schema an explicit object that can be selected and applied independently.

Their extension approaches follow those different foundations. class-validator’s rules are expressed as property decorators, so reusable constraints are associated with class fields and the metadata collected for those classes. joi’s validation is expressed through schemas, allowing a developer to compose the description of an object and its constraints as part of the validation flow. Consider whether the team prefers annotations embedded in class declarations or schemas that can be handled as separate values; neither model is simply a drop-in form of the other.

For developer experience, class-validator can be approachable when TypeScript classes are already the project’s primary way to define data: rules appear beside the properties they protect. That convenience also means developers need to understand the decorator-and-instance model, and validation depends on class structure rather than only on an object’s shape. joi requires learning its schema-oriented API, but its explicit schema makes the validation boundary easy to identify when inspecting code that handles plain objects.

The supplied bundle figures show a meaningful footprint difference: joi is listed at 55.0 kB gzip, compared with 105.8 kB for class-validator. The unpacked figures point in the same direction, at 1.9 MB for joi and 5.3 MB for class-validator. If shipped JavaScript size is an important constraint, joi has the advantage in these figures; bundle size alone, however, does not determine whether its schema model matches the application’s architecture.

Choose class-validator when the application already represents validated data as classes and the team wants constraints declared on properties, for example when class instances are the natural boundary for incoming or internal data. Choose joi when the input is primarily plain objects and a standalone schema is the clearer contract, such as validating payloads or configuration before application code consumes them. Before adopting either, test the validation flow against the actual data shape: converting plain objects into class instances or maintaining schemas beside classes can add a design layer that the other approach avoids.

The migration path is architectural rather than a mechanical change of syntax. Moving from class-validator to joi means translating property decorators into object schemas and changing validation calls to operate on those schemas; moving in the other direction means establishing classes and applying decorators to their properties. Teams should account for where constraints are currently defined and whether consumers expect class instances, because those expectations can be more consequential than rewriting individual rules.

A useful boundary case is a codebase with both class-based domain objects and untrusted, plain input data. class-validator is a closer fit where validation belongs to instances; joi is a closer fit where the schema itself should describe and check an incoming object. The provided package data also shows joi with more weekly downloads and stars, fewer open issues, and a later listed update, but those comparisons do not replace the architectural decision: pick the API that matches the data representation your validation boundary actually receives.

CORRECTIONS

Spot wrong data here?

A short note helps us fix it.

Anonymous · No account · No email back

RELATED COMPARISONS 8
ajv vs class-validator ★ 26.7K · 553.1M/wk class-validator vs ow ★ 15.7K · 20.6M/wk @sinclair/typebox vs class-validator ★ 11.9K · 184.0M/wk class-validator vs zod ★ 56.3K · 480.8M/wk class-validator vs fast-xml-parser ★ 15.0K · 132.6M/wk class-validator vs yup ★ 35.5K · 34.3M/wk class-validator vs valibot ★ 21.0K · 53.0M/wk class-validator vs superstruct ★ 19.0K · 27.7M/wk