Built-in Validator in Hono
From the Hono cheat sheet · Validation · verified Jul 2026
Built-in Validator
Use Hono's built-in validator without external deps
typescript
import { validator } from 'hono/validator'
// Custom validation function
app.post('/posts',
validator('json', (value, c) => {
const { title, body } = value
if (!title || typeof title !== 'string') {
return c.json({ error: 'Title is required' }, 400)
}
if (!body || body.length < 10) {
return c.json({ error: 'Body too short' }, 400)
}
return { title, body } // Return validated data
}),
(c) => {
const { title, body } = c.req.valid('json')
return c.json({ title, body }, 201)
}
)💡 Built-in validator works without external libraries
⚡ Return c.json() or c.text() to short-circuit with error
📌 Return validated data to pass to handler
🎯 Supports async validation for database checks