Skip to content

Installation

shorn has one dependency, @standard-schema/spec, which is types-only.

Terminal window
npm install shorn zod
# or
npm install shorn arktype
# or
npm install shorn valibot @valibot/to-json-schema

shorn is ESM-only and has no Node built-ins. Its neutral platform target runs unchanged in browsers, workers, Bun, and Deno.

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.

ValidatorVersionExtra packageCall style
Zod4.2+noneencode(Person, value)
ArkType2.1.28+noneencode(Person, value)
Valibot1.x@valibot/to-json-schemaencode(Person, value, { structure })

Any other validator that implements both interfaces works without an adapter.

  • Node 22+, or any runtime with TextEncoder, DataView, and Uint8Array.
  • TypeScript 5.x for typed results — decode returns your schema’s type instead of unknown.
  • ESM. There is no CommonJS build.
const Person = z.object({ name: z.string(), age: z.int().nonnegative() });
const bytes = encode(Person, { name: "Ada", age: 36 });
bytes.length; // 5
decode(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.