@jetio/schema-builder
A fluent, type-safe API for constructing JSON Schemas programmatically. Build complex schemas with autocomplete, validation, and zero boilerplate — and get automatic TypeScript type inference from the same build() call.
This package ships with @jetio/validatorÂ
as a dependency. You get both the builder and the validator in one install.
All core validation rules, error handling, and $data references are documented in the
Validator Documentation .
Three things from one schema
Write a schema once and build() gives you a fluent builder, a matching TypeScript type via Jet.Infer<>, and runtime validation — all enforcing the same rules, none of them able to drift apart.
import { SchemaBuilder, Jet, JetValidator } from "@jetio/schema-builder";
const userSchema = new SchemaBuilder()
.object()
.properties({
id: (s) => s.number(),
name: (s) => s.string(),
email: (s) => s.string().format("email"),
})
.required(["id", "name", "email"])
.build();
type User = Jet.Infer<typeof userSchema>;
// { id: number; name: string; email: string }
const validate = new JetValidator().compile(userSchema);
validate({ id: 1, name: "Alice", email: "alice@example.com" }); // trueWhy it’s different
- Spec-compliant inference — types behave like JSON Schema, not just resemble it. If the validator rejects it, TypeScript rejects it too.
oneOfis actually exclusive — the other branch’s keys are markedneverautomatically, giving a true discriminated union with nokindtag required.if/then/elseIf/elseare inferred — conditional types from conditional schemas, includingelseIf, which no other TypeScript schema library supports.- Full draft coverage — Draft 06 through 2020-12, including
unevaluatedProperties,prefixItems,$dynamicRef, andpatternPropertiesmapped to template-literal keys. - No
as const— literal types from.enum()and.const()are inferred for you.
Try it live
No install required — open the playground on StackBlitz →Â
Where to go next
Last updated on