colinhacks

zod

TypeScript-first schema validation with static type inference

by colinhacks

TypeScript

TypeScript89.3%
MDX9.7%
JavaScript0.5%
HTML0.5%
CSS0.1%
Shell0%

Commit activity

Last 12 weeks · 209 commits

Full graph →

Community health

4 of 6 standards met

Community profile →
85
✓README✓License✓Contributing✓Code of Conduct○Issue Template○PR Template

Recent PRs & issues

Active · Last activity 14h ago
See all on GitHub →
anthonyalayo

I have a zod object that is handed to me from elsewhere, and I do not have the ability to change it. However, I do know what items it contains. For example, it has a "firstName" string with a min length of 3 and a max length of 24. I believe at present there is no way to do something like: Could support be added for such a feature? I had requested this in https://github.com/colinhacks/zod/issues/4057 and the ticket was closed without providing the support. Multiple people upvoted my issue, so I believe it is something many people desire.

anthonyalayo · 6h ago
danieldietzler

can't validate Unicode strings, in two ways. Both break round trips of Zod's own output. 1. is compiled without the flag and go through with no flags, so is read as a literal . Turning on everywhere would break patterns that work today. , , a lone or are all valid without and throw with it. 2. is ignored, and serializes as Mapping to the ASCII check is correct, since the spec's is ASCII only. The Unicode one is , and doesn't handle it. Proposed fix Compile and with , and fall back to no flags on a so existing patterns keep working. Map to . Optionally, have emit when the email pattern is or , so the round trip holds. Found while importing the Immich OpenAPI 3.1 spec, whose email fields use a pattern, with zod 4.6.7. I checked that main (19c40d2) is the same.

danieldietzler · 1d ago
abd1rahmane

starts with `packages/zod/logo.svgpackages/zodpackage/README.mdlogo.svghttps://raw.githubusercontent.com/colinhacks/zod/main/logo.svgpackages/zodpackages/zod/package.jsonfiles` or it will not be published.

abd1rahmane · 1d ago
anthonyalayo

I have a zod object that is handed to me from elsewhere, and I do not have the ability to change it. However, I do know what items it contains. For example, it has a "firstName" string with a min length of 3 and a max length of 24. I believe at present there is no way to do something like: Could support be added for such a feature?

anthonyalayo · 8h ago
colinhacks

Since 4.6.0, emits , and for , and . None of those are JSON Schema formats, so ajv warns about them. Chained after a real format, the later check also overwrote it: exported in place of , which lets accept input Zod rejects. These three checks now contribute only their , as in 4.5.x. A format set by , or similar is kept in either chain order, and / still emit their own format. The converter tells them apart by the trait rather than a list of names. Output matches across 24 schemas on , and , apart from the email regex text, which changed independently. Bundle: +12 B gzip classic, +9 B gzip mini ( fixtures). Runtime: no measurable change in (interleaved, load ~60, indicative); parse paths are untouched. Memory: no new properties or closures. Closes #6648 Thanks to @MFA-G for the original fix and test.

colinhacks · 1d ago
Vivswan

Since zod 4.6.0 (#6554, "derive JSON Schema constraints by folding checks in the converter"), copies every check's name into the JSON Schema keyword. For , , and that name is not a JSON Schema format, so validators such as ajv report . Reproduction on zod 4.6.5 (bun 1.4): Output: On 4.5.4 the same schemas emit only the . Expected: the alone, since it already carries the constraint, and only for names JSON Schema (or zod's documented format set) defines. Where it comes from: copies from every check, and // construct their checks with and the internal names above. Fix Branch, ready to open as a PR by a collaborator (this repository refuses PR creation from my account): https://github.com/colinhacks/zod/compare/main...Vivswan:zod:fix/json-schema-string-format-trait One change in : a check contributes a only if it carries the trait. Why that works: , and are built with , not . That is why they never wrote on 4.5.x. Test: fails on with received, passes on the branch. Full suite green. Bundle: unchanged unless is used, then +31 gzip bytes classic, +30 mini. Trait read, not :** pulls into mini bundles that never build a format check (+89 bytes).

Vivswan · 1d ago
Structured data for AI agents

Repository: colinhacks/zod. Description: TypeScript-first schema validation with static type inference Stars: 44326, Forks: 2347. Primary language: TypeScript. Languages: TypeScript (89.3%), MDX (9.7%), JavaScript (0.5%), HTML (0.5%), CSS (0.1%). License: MIT. Homepage: https://zod.dev Topics: runtime-validation, schema-validation, static-types, type-inference, typescript. Latest release: v4.6.7 (1mo ago). Open PRs: 17, open issues: 105. Last activity: 14h ago. Community health: 85%. Top contributors: colinhacks, JacobWeisenburger, scotttrinh, pullfrog[bot], jeremyBanks, samchungy, igalklebanov, tmcw, noritaka1166, alexxander and others.