@hono/zod-validator

Type-safe request validation middleware for Hono, powered by Zod schemas.

Library
npm
v0.9.1
1,000 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
91 /100 Excellent
Development Activity 96
Maintenance 100
Community 72
Maturity 56
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
87 /100 Excellent
Architecture 86
Code Quality 85
Innovation 90
Learning Curve 85

@hono/zod-validator is the official validation middleware for the Hono web framework, bridging Zod’s schema-based validation into the request pipeline. Define a Zod schema, wrap it in the zValidator helper, and every incoming JSON body, query string, route parameter, form field, or header is validated before your handler runs.

Beyond runtime checks, the middleware infers the fully-typed validated value so c.req.valid('json') returns a strongly-typed object with no manual casting. It supports both Zod v3 and v4, custom validation functions, and error hooks that let you shape or short-circuit invalid responses.

What You Get

  • A single zValidator helper that validates any request target: json, form, query, param, header, or cookie
  • End-to-end type inference so c.req.valid(target) returns the schema’s output type with no manual casting
  • Support for both Zod v3 and Zod v4 schemas from the same API
  • An optional hook to customize error responses or throw instead of returning the default 400
  • A validationFunction option to override the default safeParseAsync behavior (e.g. passthrough parsing)

Common Use Cases

  • Validating and typing JSON request bodies for REST and RPC-style Hono APIs
  • Guarding query strings and route parameters before business logic executes
  • Normalizing and validating request headers with case-insensitive key matching
  • Returning consistent, structured 400 error payloads for malformed input

Under The Hood

Architecture The entire package is a single src/index.ts that exports one function, zValidator, aliased over an internal zValidatorFunction. That function delegates to Hono’s built-in validator(target, cb) from hono/validator, supplying an async callback that runs the schema against the request target. When the target is header, it first remaps Hono’s lowercased header keys back to the schema’s original keys via a case-insensitive keymap. It then calls schema.safeParseAsync (or a user-supplied validationFunction), passes the result through an optional hook, returns c.json(result, 400) on failure, and otherwise hands the typed result.data back to Hono to expose via c.req.valid(target).

Tech Stack Written entirely in TypeScript and shipped as dual ESM/CJS via tsdown. It declares hono (>=4.11.2) and zod (^3.25 || ^4) as peer dependencies, so it carries no runtime dependencies of its own. It publishes to npm with provenance and also targets JSR/Deno (a deno.json is present). Tests run under Vitest.

Code Quality The package is small but heavily type-driven: overloaded signatures distinguish the hook and non-hook call forms, and conditional types (ZodError, zInfer, ExtractValidationResponse) derive precise input/output and error-response types across both Zod v3 and v4. Test coverage is explicit, with separate v3.test.ts and v4.test.ts suites exercising each supported Zod major version. A handful of @ts-expect-error pragmas bridge the two Zod type systems where their internal shapes diverge.

API Design The public surface is a single, well-named zValidator(target, schema, hook?, options?) helper, which keeps the learning curve low: one import, one call per route. Type inference means callers rarely annotate anything, and the README documents the common patterns (basic validation, error hooks, throwing errors, custom validation functions) with concise runnable snippets.

Used by 69 apps in this directory

TypeScript
98%
Other

Dokploy

Devops · Hosting Control Panel · Security

37,989

Self-hosted PaaS that deploys apps and databases on your own VPS using Docker, Traefik, and multi-build-system orchestration

View details
89
Repo Health
76
Technical
64
Dependency
Built with
TypeScript 98%
Updated 5 days ago
TypeScript
64%
Other

Epicenter

Developer Tools · Knowledge Management · Note Taking

4,825

A local-first monorepo led by Whispering, an open-source speech-to-text app, built on an MIT toolkit that turns your data into plain Markdown and SQLite files you own instead of a database you rent.

View details
87
Repo Health
90
Technical
64
Dependency
Built with
TypeScript 64%
Rust 15%
Updated 1 weeks ago
TypeScript
94%
Apache 2.0

flue

AI Agents · Developer Tools

8,521

Build autonomous AI agents and powerful workflows with a programmable TypeScript harness that gives any model sessions, tools, sandboxes, and durable execution.

View details
81
Repo Health
82
Technical
69
Dependency
Built with
TypeScript 94%
Updated 1 weeks ago
MDX
50%
Apache 2.0

Formizee

Forms Surveys

184

An open-source form backend and builder platform — design forms, collect submissions, and get analytics without hosting your own server, positioned as an alternative to Formspree and Typeform.

View details
30
Repo Health
59
Technical
67
Dependency
Built with
MDX 50%
TypeScript 49%
Updated 1 years ago
TypeScript
92%
MIT

Kaneo

Product Management · Productivity · Project Management

9,574

Lightweight self-hosted project management that gives you kanban boards, GitHub sync, and full team collaboration without the enterprise bloat.

View details
87
Repo Health
81
Technical
70
Dependency
Built with
TypeScript 92%
Updated 5 days ago
TypeScript
92%
MIT

Kaneo

Product Management · Productivity · Project Management

9,574

Lightweight self-hosted project management that gives you kanban boards, GitHub sync, and full team collaboration without the enterprise bloat.

View details
87
Repo Health
81
Technical
70
Dependency
Built with
TypeScript 92%
Updated 5 days ago
TypeScript
98%
AGPL 3.0

Karakeep

Bookmarks Archiving

29,926

Self-hosted bookmark manager that captures links, notes, images, and PDFs with AI tagging, full-text search, and automatic archiving.

View details
88
Repo Health
76
Technical
66
Dependency
Built with
TypeScript 98%
Updated 1 weeks ago
TypeScript
98%
AGPL 3.0

Karakeep

Bookmarks Archiving

29,926

Self-hosted bookmark manager that captures links, notes, images, and PDFs with AI tagging, full-text search, and automatic archiving.

View details
88
Repo Health
76
Technical
66
Dependency
Built with
TypeScript 98%
Updated 1 weeks ago
TypeScript
98%
AGPL 3.0

Karakeep

Bookmarks Archiving

29,926

Self-hosted bookmark manager that captures links, notes, images, and PDFs with AI tagging, full-text search, and automatic archiving.

View details
88
Repo Health
76
Technical
66
Dependency
Built with
TypeScript 98%
Updated 1 weeks ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers