Installation
shorn has one dependency, @standard-schema/spec, which is types-only.
npm install shorn zod# ornpm install shorn arktype# ornpm install shorn valibot @valibot/to-json-schemashorn is ESM-only and has no Node built-ins. Its neutral platform target runs unchanged in browsers, workers, Bun, and Deno.
Which validator needs what
Section titled “Which validator needs what”shorn uses Standard Schema for validation and Standard JSON Schema for structure. Some validators provide both interfaces on one object; others need an extra converter.
| Validator | Version | Extra package | Call style |
|---|---|---|---|
| Zod | 4.2+ | none | encode(Person, value) |
| ArkType | 2.1.28+ | none | encode(Person, value) |
| Valibot | 1.x | @valibot/to-json-schema | encode(Person, value, { structure }) |
Any other validator that implements both interfaces works without an adapter.
Requirements
Section titled “Requirements”- Node 22+, or any runtime with
TextEncoder,DataView, andUint8Array. - TypeScript 5.x for typed results —
decodereturns your schema’s type instead ofunknown. - ESM. There is no CommonJS build.
Verify
Section titled “Verify”const Person = z.object({ name: z.string(), age: z.int().nonnegative() });const bytes = encode(Person, { name: "Ada", age: 36 });
bytes.length; // 5decode(Person, bytes); // { name: "Ada", age: 36 }An EncodeError here means the schema uses an unsupported shape. Rejected Shapes lists each unsupported shape and what to use instead.