Skip to content

Introduction

shorn encodes data with the schema your project already uses. It reads Standard Schema for validation and Standard JSON Schema for structure. Field names and type tags stay in the schema instead of being repeated in every payload.

import { z } from "zod";
import { decode, encode } from "shorn";
const Person = z.object({
name: z.string(),
age: z.int().nonnegative(),
sex: z.enum(["M", "F", "X"]),
});
const bytes = encode(Person, person); // 8 bytes
const decoded = decode(Person, bytes);

The same value is 35 bytes of minified JSON.

  • No shorn schema language. No IDL, CLI, codegen, or compiler plugin.
  • Canonical bytes. Equivalent Zod, Valibot, and ArkType schemas encode identically.
  • Validation both ways. Your library runs on encode and again on decode.
  • 5.39 KB gzip runtime, the smallest codec in the measured comparison, tree-shaken per feature.
  • MIT licensed.

shorn is an experimental alpha with important limits:

  • No schema evolution. Only the schema that wrote a payload can decode it. fingerprinted() detects a mismatch; nothing resolves one.
  • No streaming, random access, or zero-copy views.
  • No cross-language decoder. TypeScript and JavaScript only.
  • Not the fastest. Avro encodes faster. msgpackr shared records decode nested and batch data faster. shorn beats JSON in both directions on every measured fixture; see Throughput.
  • Not confidential. Encrypt the bytes when secrecy matters.
ToRead
Understand the pitchWhy shorn?
Get runningInstallation, Quick Start
Know what encodesSupported Types
Store or queue payloadsFingerprinting — not optional
See the bytesByte Layout