Repository navigation
shorn: your Zod schema already describes the payload, so why send the keys? #6375
|
I built shorn. It uses the Zod schema you already have as a binary wire format. Both sides have the schema, so field names never go in the payload. const Person = z.object({
name: z.string(),
age: z.int().nonnegative(),
sex: z.enum(["male", "female", "other"]),
});
const bytes = encode(Person, { name: "Colin", age: 24, sex: "male" });
// keys live in Person, so only the values go out: ["Colin", 24, "male"] in binary format
// 8 bytes, against 38 as minified JSON
decode(Person, bytes); // { name: "Colin", age: 24, sex: "male" }It's also faster. JSON has to write every key and parse it back out again. shorn skips that work entirely, so it's up to 6.2x faster to encode and 14.5x to decode in my benchmarks. The saving comes from the schema, not from compression, so there's no CPU cost to pay for it. No IDL, no codegen, no second schema. It reads validation through Standard Schema and structure through Standard JSON Schema. Playground: https://shorn.dev One question, since I depend on it: how stable is the |
Replies: 2 comments
|
Hi @ChiChuRita! I'm Dosu and I'm helping the Zod team. shorn sounds like a really clever idea — using the schema as the wire format is an elegant reuse of something you're already paying for. On your stability question: Here's what I can tell you about the specific keywords you depend on:
What has changed recently: v4.4.0 shipped a fix where Practical advice: Pin to a specific For the most authoritative answer on stability guarantees, you'd want to hear from @colinhacks directly — I'm not aware of any explicit written promise on To reply, just mention @dosu. Share context across your team and agents. Try Dosu. |
Stability of
|
Stability of
z.toJSONSchema()in Zod 4To answer your core question directly: The output structure of
z.toJSONSchema()for standard primitives and structural combinators is treated as stable and normative under SemVer, specifically because the wider ecosystem (OpenAPI generators, AI function-calling schemas, and tooling) depends on deterministic output.Here is what you can rely on, along with two critical architectural caveats for binary wire serialization:
1. What is Guaranteed and Stable
Zod 4’s
toJSONSchematargets JSON Schema Draft 2020-12. This means:prefixItems(not the obsolete Draft 7 array-of-schemas…