Valibot
Generate Valibot schemas from JSON Schema definitions
The Valibot adapter converts JSON Schema definitions into Valibot validation schemas with full TypeScript type inference.
Overview
- Package:
@xschemadev/valibot - Peer Dependency:
valibot ^0.42.0 - Compliance: 98.9%
Valibot is a modular validation library focused on bundle size. xschema's Valibot adapter provides:
- Near-complete compliance with JSON Schema specifications (98.9% for draft2020-12)
- Full type inference - generated schemas include TypeScript types
- Tree-shakeable - only include what you use
- Minimal bundle size - modular design keeps bundles small
Installation
bun add @xschemadev/valibot valibotnpm install @xschemadev/valibot valibotpnpm add @xschemadev/valibot valibotyarn add @xschemadev/valibot valibotUsage
{
"$schema": "https://xschema.dev/schemas/typescript.jsonc",
"schemas": [
{
"id": "User",
"adapter": "@xschemadev/valibot",
"source": "./user.schema.json"
}
]
}import { } from "./client";
import * as from "valibot";
const user = .(("User"), { : "1", : "Alice", : "alice@example.com" });See the TypeScript guide for full setup instructions.
Supported Features
The Valibot adapter supports most JSON Schema keywords. See the Compliance page for detailed coverage by JSON Schema draft.
Known Limitation
Valibot has a bug where object properties with prototype-related names cause runtime errors:
__proto__constructortoString
When validating an object schema that includes any of these property names, Valibot throws:
this.entries[key]._run is not a functionThis is a Valibot library bug, not an xschema issue. The generated code is correct, but Valibot's internal object handling conflicts with JavaScript's prototype chain.
Workaround: Avoid using these property names in your JSON Schemas when using the Valibot adapter. If you need to support schemas with these property names, consider using a different adapter like Zod or ArkType, which have 100% compliance.
Bundle Size Advantage
Valibot's modular design means generated schemas only include the validators actually used:
// Only these functions are included in your bundle
import { object, string, optional, number, pipe, minLength } from "valibot";This makes Valibot an excellent choice for frontend applications where bundle size matters.