COMPARISON · VALIDATION

ajv vs. class-validator

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

ajv v8.20.0 · MIT
Weekly Downloads
535.1M
Stars
14.9K
Gzip Size
36.1 kB
License
MIT
Last Updated
9mo ago
Open Issues
411
Forks
1.1K
Unpacked Size
1.0 MB
Dependencies
4
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
DOWNLOAD TRENDS

ajv vs class-validator downloads · last 12 months

Download trends for ajv and class-validator2 download series from Nov 2025 to Oct 2026. Use left and right arrow keys to inspect monthly values.0461.9M923.9M1385.8M1847.8MNov 2025FebMayAugOct 2026
ajv
class-validator
FEATURE COMPARISON

Criteria · ajv vs class-validator

Data Model Fit
ajv
Fits plain JSON data and schema-described payloads
class-validator
Fits class-shaped data with property-level rules
Learning Focus
ajv
Requires working with JSON Schema as the validation representation
class-validator
Requires working with decorator-based property rules
Rule Placement
ajv
Keeps constraints in a schema separate from data classes
class-validator
Keeps constraints alongside class properties
Contract Migration
ajv
Moving away requires translating schema-based rules
class-validator
Moving away requires translating decorated class rules
Schema Portability
ajv ✓
Uses JSON Schema as its central validation representation
class-validator
Centers rules on decorated class definitions
Validation Contract
ajv
Defines validation through JSON Schema documents
class-validator
Defines validation through decorators on class properties
Reported Issue Count
ajv
390 open issues in the supplied snapshot
class-validator ✓
320 open issues in the supplied snapshot
Contract Organization
ajv
Maintains a distinct schema-based contract
class-validator
Maintains the contract with class declarations
Application Boundary Fit
ajv
Suitable for checking JSON payloads against schemas
class-validator
Suitable when boundary data is modeled as classes
Decorator-Based Modeling
ajv
Does not center its stated approach on decorators
class-validator ✓
Uses decorators to declare property validation
Validation of Plain JSON
ajv ✓
Schema-first approach directly targets JSON data
class-validator
Class-property approach is oriented around class models
Class-Oriented Validation
ajv
Validation contract is represented by schemas
class-validator ✓
Validation rules are attached to class properties
Reported Bundle Footprint
ajv ✓
Smaller reported gzip bundle at 36.1 kB
class-validator
Larger reported gzip bundle at 105.8 kB
Reported Unpacked Footprint
ajv ✓
Smaller reported unpacked size at 1.0 MB
class-validator
Larger reported unpacked size at 5.3 MB
VERDICT

ajv is best suited to validating JSON data against explicitly defined JSON Schema documents. Its schema-centered approach fits API payloads, configuration files, and other data that needs to be checked independently of application classes; the package description and topics identify JSON Schema as its focus. Teams that want validation rules expressed in a schema, rather than attached to class properties, should start by evaluating ajv.

class-validator is designed for developers who represent data as classes and want validation rules declared with decorators on class properties. That approach can keep constraints close to TypeScript-oriented domain or request classes, which may suit applications whose data already follows a class-based model. Its value is strongest when property-level declarations are a better fit than maintaining separate JSON Schema documents.

The central architectural difference is the object being described: ajv validates data against a schema, while class-validator describes constraints through decorators on class properties. With ajv, the schema is the validation contract and can be treated as a distinct artifact; with class-validator, the class and its decorators carry the contract together. This affects how teams share rules, review changes, and validate data that does not naturally arrive as an instance of a class.

The extension approach follows that same distinction. ajv is organized around JSON Schema, so its central extension surface is schema-based validation; class-validator is organized around decorators, so its rules are attached to properties and expressed through that class-oriented pattern. Choose based on where you want validation logic to live: in a schema that describes data, or on a class that represents it. The supplied package information does not establish specific extension features beyond those core designs.

For developer experience, class-validator may feel direct when developers already work with decorated classes: they can read property declarations and their validation rules together. ajv asks developers to learn and maintain JSON Schema as a separate validation representation, but that separation can be useful when data contracts need to be inspected or handled apart from application classes. The available information does not specify comparative TypeScript ergonomics, error formats, or debugging tools, so those details should be checked against the intended integration rather than assumed.

The size figures favor ajv for applications where dependency footprint matters: its reported gzip bundle is 36.1 kB, compared with 105.8 kB for class-validator, and its unpacked size is 1.0 MB versus 5.3 MB. That makes ajv the more compact reported option, though the figures alone do not establish runtime speed or total application impact. The download counts also differ substantially, at 159.4M weekly for ajv and 4.6M for class-validator, while the supplied data provides no benchmark results to support a performance claim.

Pick ajv when an API boundary, configuration loader, or data-processing service needs JSON Schema validation, especially when the data is plain JSON rather than class instances. Pick class-validator when the application already models validated inputs as classes and decorators are the preferred place to declare property constraints. If a project has both needs, decide which representation is the authoritative contract before introducing parallel rules that can drift apart.

Adopting either package creates a different maintenance commitment: ajv places the contract in schemas, whereas class-validator places it alongside class properties. Moving between them therefore means translating not only individual constraints but also the way contracts are organized and consumed. ajv has more reported GitHub stars and forks, while class-validator has fewer open issues in the supplied snapshot; these figures provide context but do not determine fit or guarantee a maintenance outcome.

A useful edge case is validation of data that has no natural class representation, such as arbitrary JSON received at a boundary: ajv’s schema-first model maps directly to that task. Conversely, when validated values are already class-shaped and property declarations are central to the codebase, class-validator avoids making a separate schema the primary expression of those rules. For either choice, verify the exact constraints and error behavior required by the application, since the supplied package data does not enumerate individual validation capabilities.

CORRECTIONS

Spot wrong data here?

A short note helps us fix it.

Anonymous · No account · No email back

RELATED COMPARISONS 8
ajv vs valibot ★ 24.0K · 570.2M/wk ajv vs joi ★ 36.1K · 568.7M/wk ajv vs yup ★ 38.5K · 551.5M/wk ajv vs zod ★ 59.3K · 997.9M/wk ajv vs superstruct ★ 22.0K · 544.9M/wk ajv vs fast-xml-parser ★ 18.0K · 649.7M/wk @sinclair/typebox vs ajv ★ 14.9K · 701.2M/wk ajv vs ow ★ 18.7K · 537.8M/wk