yarn zod 4.2.0
v4.2.0

latest releases: 4.3.0-canary.20251216T172808, 4.3.0-canary.20251216T031837, 4.3.0-canary.20251216T031750...
one day ago

Features

Implement Standard JSON Schema

standard-schema/standard-schema#134

Implement z.fromJSONSchema()

const jsonSchema = {
  type: "object",
  properties: {
    name: { type: "string" },
    age: { type: "number" }
  },
  required: ["name"]
};

const schema = z.fromJSONSchema(jsonSchema);

Implement z.xor()

const schema = z.xor(
  z.object({ type: "user", name: z.string() }),
  z.object({ type: "admin", role: z.string() })
);
// Exactly one of the schemas must match

Implement z.looseRecord()

const schema = z.looseRecord(z.string(), z.number());
// Allows additional properties beyond those defined

Commits:

  • af49c08 Update docs for JSON Schema conversion of z.undefined() (#5504)
  • 767f320 Add .toJSONSchema() method (#5477)
  • e17dcb6 Add z.fromJSONSchema(), z.looseRecord(), z.xor() (#5534)

Don't miss a new zod release

NewReleases is sending notifications on new releases.