Repository navigation
Codecs, real async parsing, and the remaining Zod 4 API surface.
Published to npm with SLSA provenance via an OIDC trusted publisher.
Added
- Codecs —
z.codec(input, output, { decode, encode })plusz.encode/decode/
safeEncode/safeDecode(and*Async) and matching methods on every schema. Encoding runs
the schema backwards through codecs, pipes andz.stringbool(), and refuses one-way
.transform()s with aZodEncodeError. - Real async parsing —
.parseAsync()/.safeParseAsync()/.spa()await async
refinements, superRefinements, transforms and.check()callbacks, including when nested in
objects, arrays, tuples, records, sets, maps, unions and wrappers. A synchronous.parse()
that meets one throwsZodAsyncErrorinstead of leaking a Promise. - Error helpers —
z.treeifyError(),z.flattenError(),z.formatError(), all with the
optional issue mapper.ZodErroris now anErrorwith a lazily built.stackand gains
.isEmpty,.addIssue(),.addIssues(). - Top-level functional API —
z.parse/safeParse/parseAsync/safeParseAsync,
z.transform,z.catch,z.default,z.prefault,z.nullish,z.nonoptional,
z.readonly,z.exactOptional,z.keyof,z.clone,z.xor,z.stringFormat,
z.slugify,z.describe,z.meta,z.fromJSONSchema. - Constants and namespaces —
z.NEVER,z.TimePrecision,z.ZodIssueCode,z.$brand,
z.regexes,z.util,z.core,z.locales,z.config(),z.getErrorMap(),
z.setErrorMap(), and runtimez.ZodString/z.ZodObject/ … class aliases. - Schema introspection —
.type,.apply(),.with(),.toJSONSchema(),.spa()on
every schema, plus.format/.minValue/.maxValue/.isInton numbers,.minDate/
.maxDateon dates,.elementon arrays,.keyType/.valueTypeon records and maps. z.object().safeExtend(),z.tuple(items, rest),z.map().min/max/size/nonempty(),
z.function().implementAsync(),z.string().slugify().z.toJSONSchema()acceptstarget,metadata,unrepresentable,overrideandio, and
emits Zod's document shape..meta()registers inz.globalRegistry.
Changed
- Issues carry Zod 4 codes natively (
invalid_format,invalid_value,invalid_union); Zod 3
spellings passed toctx.addIssue()are still accepted and normalised. .prefault(v)runs the fallback through the schema;.default(v)still short-circuits..transform()receives Zod'sctx;.catch()receives{ value, issues, error, input };
.refine()accepts{ when, abort, path, message, error }.z.prettifyError()uses Zod's layout;error.flatten()keysfieldErrorslike Zod..extend(),.pick(),.omit(),.partial(),.required()keep the object's unknown-key
policy.z.discriminatedUnion()resolves discriminators through optional, nullable, enum and
nested-union options.
Performance
Zig core JSON parse/validate paths use a stack-owned arena instead of a heap-allocated
Parsed wrapper, and json_batch_validator is now part of zig build test. (#80)
The differential parity suite is now 283 schemas / 4,961 checks against zod@4.3.6 with zero
mismatches, and dhi remains faster than Zod on every benchmark row.