{"name":"zod","version":"4.4.2","keywords":["typescript","schema","validation","type","inference"],"author":{"name":"Colin McDonnell","email":"zod@colinhacks.com"},"license":"MIT","_id":"zod@4.4.2","maintainers":[{"name":"colinhacks","email":"colinmcd94@gmail.com"}],"homepage":"https://zod.dev","bugs":{"url":"https://github.com/colinhacks/zod/issues"},"dist":{"shasum":"5e53a8c23fc7050b9960d441002e9c9fca33c99e","tarball":"http://registry-npm.ywwl.com/zod/download/zod-4.4.2.tgz","fileCount":718,"integrity":"sha512-IynmDyxsEsb9RKzO3J9+4SxXnl2FTFSzNBaKKaMV6tsSk0rw9gYw9gs+JFCq/qk2LCZ78KDwyj+Z289TijSkUw==","signatures":[{"sig":"MEUCIQCCQPm0PumRBiNJzoYQSaili9tLZEuGl5H3OuBlEND5PAIgEVtkchsDl+E+SV6SkiBaG01uqoAaYmGCmyTAwQGmEQI=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/zod@4.4.2","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":4554838,"size":758715,"noattachment":false,"key":"/zod/-/zod-4.4.2.tgz"},"llms":"https://zod.dev/llms.txt","main":"./index.cjs","type":"module","zshy":{"exports":{".":"./src/index.ts","./v3":"./src/v3/index.ts","./v4":"./src/v4/index.ts","./mini":"./src/mini/index.ts","./locales":"./src/locales/index.ts","./v4-mini":"./src/v4-mini/index.ts","./v4/core":"./src/v4/core/index.ts","./v4/mini":"./src/v4/mini/index.ts","./v4/locales":"./src/v4/locales/index.ts","./package.json":"./package.json","./v4/locales/*":"./src/v4/locales/*"},"conditions":{"@zod/source":"src"}},"types":"./index.d.cts","module":"./index.js","exports":{".":{"types":"./index.d.cts","import":"./index.js","require":"./index.cjs","@zod/source":"./src/index.ts"},"./v3":{"types":"./v3/index.d.cts","import":"./v3/index.js","require":"./v3/index.cjs","@zod/source":"./src/v3/index.ts"},"./v4":{"types":"./v4/index.d.cts","import":"./v4/index.js","require":"./v4/index.cjs","@zod/source":"./src/v4/index.ts"},"./mini":{"types":"./mini/index.d.cts","import":"./mini/index.js","require":"./mini/index.cjs","@zod/source":"./src/mini/index.ts"},"./locales":{"types":"./locales/index.d.cts","import":"./locales/index.js","require":"./locales/index.cjs","@zod/source":"./src/locales/index.ts"},"./v4-mini":{"types":"./v4-mini/index.d.cts","import":"./v4-mini/index.js","require":"./v4-mini/index.cjs","@zod/source":"./src/v4-mini/index.ts"},"./v4/core":{"types":"./v4/core/index.d.cts","import":"./v4/core/index.js","require":"./v4/core/index.cjs","@zod/source":"./src/v4/core/index.ts"},"./v4/mini":{"types":"./v4/mini/index.d.cts","import":"./v4/mini/index.js","require":"./v4/mini/index.cjs","@zod/source":"./src/v4/mini/index.ts"},"./v4/locales":{"types":"./v4/locales/index.d.cts","import":"./v4/locales/index.js","require":"./v4/locales/index.cjs","@zod/source":"./src/v4/locales/index.ts"},"./package.json":"./package.json","./v4/locales/*":{"types":"./v4/locales/*","import":"./v4/locales/*","require":"./v4/locales/*","@zod/source":"./src/v4/locales/*"}},"funding":"https://github.com/sponsors/colinhacks","gitHead":"c59d4474e3b4cad1b323462186cf607178ce8267","scripts":{"test":"pnpm vitest run","build":"zshy --project tsconfig.build.json","clean":"git clean -xdf . -e node_modules","postbuild":"tsx ../../scripts/write-stub-package-jsons.ts && pnpm biome check --write .","test:watch":"pnpm vitest","prepublishOnly":"tsx ../../scripts/check-versions.ts"},"support":{"backing":{"npm-funding":true}},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:27618225-ea3e-490f-a88f-ee02eafa1ade"}},"llmsFull":"https://zod.dev/llms-full.txt","mcpServer":"https://mcp.inkeep.com/zod/mcp","repository":{"url":"git+https://github.com/colinhacks/zod.git","type":"git"},"_npmVersion":"11.13.0","description":"TypeScript-first schema declaration and validation library with static type inference","directories":{},"sideEffects":false,"_nodeVersion":"24.14.1","_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/zod_4.4.2_1777671003567_0.25174472882523813","host":"s3://npm-registry-packages-npm-production"},"readme":"<p align=\"center\">\n  <img src=\"logo.svg\" width=\"200px\" align=\"center\" alt=\"Zod logo\" />\n  <h1 align=\"center\">Zod</h1>\n  <p align=\"center\">\n    TypeScript-first schema validation with static type inference\n    <br/>\n    by <a href=\"https://x.com/colinhacks\">@colinhacks</a>\n  </p>\n</p>\n<br/>\n\n<p align=\"center\">\n<a href=\"https://github.com/colinhacks/zod/actions?query=branch%3Amain\"><img src=\"https://github.com/colinhacks/zod/actions/workflows/test.yml/badge.svg?event=push&branch=main\" alt=\"Zod CI status\" /></a>\n<a href=\"https://opensource.org/licenses/MIT\" rel=\"nofollow\"><img src=\"https://img.shields.io/github/license/colinhacks/zod\" alt=\"License\"></a>\n<a href=\"https://www.npmjs.com/package/zod\" rel=\"nofollow\"><img src=\"https://img.shields.io/npm/dw/zod.svg\" alt=\"npm\"></a>\n<a href=\"https://discord.gg/KaSRdyX2vc\" rel=\"nofollow\"><img src=\"https://img.shields.io/discord/893487829802418277?label=Discord&logo=discord&logoColor=white\" alt=\"discord server\"></a>\n<a href=\"https://github.com/colinhacks/zod\" rel=\"nofollow\"><img src=\"https://img.shields.io/github/stars/colinhacks/zod\" alt=\"stars\"></a>\n</p>\n\n<div align=\"center\">\n  <a href=\"https://zod.dev/api\">Docs</a>\n  <span>&nbsp;&nbsp;•&nbsp;&nbsp;</span>\n  <a href=\"https://discord.gg/RcG33DQJdf\">Discord</a>\n  <span>&nbsp;&nbsp;•&nbsp;&nbsp;</span>\n  <a href=\"https://twitter.com/colinhacks\">𝕏</a>\n  <span>&nbsp;&nbsp;•&nbsp;&nbsp;</span>\n  <a href=\"https://bsky.app/profile/zod.dev\">Bluesky</a>\n  <br />\n</div>\n\n<br/>\n<br/>\n\n### [Read the docs →](https://zod.dev/api)\n\n<br/>\n<br/>\n\n## What is Zod?\n\nZod is a TypeScript-first validation library. Define a schema and parse some data with it. You'll get back a strongly typed, validated result.\n\n```ts\nimport * as z from \"zod\";\n\nconst User = z.object({\n  name: z.string(),\n});\n\n// some untrusted data...\nconst input = {\n  /* stuff */\n};\n\n// the parsed result is validated and type safe!\nconst data = User.parse(input);\n\n// so you can use it with confidence :)\nconsole.log(data.name);\n```\n\n<br/>\n\n## Features\n\n- Zero external dependencies\n- Works in Node.js and all modern browsers\n- Tiny: `2kb` core bundle (gzipped)\n- Immutable API: methods return a new instance\n- Concise interface\n- Works with TypeScript and plain JS\n- Built-in JSON Schema conversion\n- Extensive ecosystem\n\n<br/>\n\n## Installation\n\n```sh\nnpm install zod\n```\n\n<br/>\n\n## Basic usage\n\nBefore you can do anything else, you need to define a schema. For the purposes of this guide, we'll use a simple object schema.\n\n```ts\nimport * as z from \"zod\";\n\nconst Player = z.object({\n  username: z.string(),\n  xp: z.number(),\n});\n```\n\n### Parsing data\n\nGiven any Zod schema, use `.parse` to validate an input. If it's valid, Zod returns a strongly-typed _deep clone_ of the input.\n\n```ts\nPlayer.parse({ username: \"billie\", xp: 100 });\n// => returns { username: \"billie\", xp: 100 }\n```\n\n**Note** — If your schema uses certain asynchronous APIs like `async` [refinements](https://zod.dev/api#refinements) or [transforms](https://zod.dev/api#transforms), you'll need to use the `.parseAsync()` method instead.\n\n```ts\nconst schema = z.string().refine(async (val) => val.length <= 8);\n\nawait schema.parseAsync(\"hello\");\n// => \"hello\"\n```\n\n### AOT compilation\n\nFor hot validation paths, `z.compile(schema)` returns a schema clone with an ahead-of-time compiled fast path. Valid inputs take the compiled path; invalid inputs fall back to the regular parser so error reporting stays identical.\n\nAcross a 55-schema benchmark the median speedup is **2.4x**, and it scales with how much work the schema does per parse: a large array of objects is ~9x, a 20-key object ~9x, a nested object ~4.5x, while a bare `z.string()` gains nothing — compilation removes per-node dispatch and allocation, and a single `typeof` has none to remove.\n\n```ts\nconst CompiledPlayer = z.compile(Player);\n\nCompiledPlayer.parse({ username: \"billie\", xp: 100 });\n```\n\nTo enable compilation globally for schemas constructed after import:\n\n```ts\nimport \"zod/compile\"; // place before modules that define schemas\n```\n\nThings to know:\n\n- Compilation uses `new Function`. Global mode is automatically disabled when `z.config({ jitless: true })` is set (e.g. CSP environments); calling `z.compile()` directly is an explicit opt-in.\n- Schemas with async refinements or transforms can't be compiled, and neither can a few other constructs. That is not an error: `z.compile()` hands the schema back unchanged and it keeps using the regular parser, exactly as global mode leaves it. Pass `{ strict: true }` to throw `ZodCompileAsyncError` / `ZodCompileUnsupportedError` instead.\n- On invalid input, refinements and transforms may run twice (fast path, then fallback).\n- Deriving a new schema from a compiled one (`.refine()`, `.extend()`, etc.) returns an uncompiled schema — compile the final schema.\n\nSee [`compile` docs](https://zod.dev/compile) for details.\n\n### Handling errors\n\nWhen validation fails, the `.parse()` method will throw a `ZodError` instance with granular information about the validation issues.\n\n```ts\ntry {\n  Player.parse({ username: 42, xp: \"100\" });\n} catch (err) {\n  if (err instanceof z.ZodError) {\n    err.issues;\n    /* [\n      {\n        expected: 'string',\n        code: 'invalid_type',\n        path: [ 'username' ],\n        message: 'Invalid input: expected string'\n      },\n      {\n        expected: 'number',\n        code: 'invalid_type',\n        path: [ 'xp' ],\n        message: 'Invalid input: expected number'\n      }\n    ] */\n  }\n}\n```\n\nTo avoid a `try/catch` block, you can use the `.safeParse()` method to get back a plain result object containing either the successfully parsed data or a `ZodError`. The result type is a [discriminated union](https://www.typescriptlang.org/docs/handbook/2/narrowing.html#discriminated-unions), so you can handle both cases conveniently.\n\n```ts\nconst result = Player.safeParse({ username: 42, xp: \"100\" });\nif (!result.success) {\n  result.error; // ZodError instance\n} else {\n  result.data; // { username: string; xp: number }\n}\n```\n\n**Note** — If your schema uses certain asynchronous APIs like `async` [refinements](https://zod.dev/api#refinements) or [transforms](https://zod.dev/api#transforms), you'll need to use the `.safeParseAsync()` method instead.\n\n```ts\nconst schema = z.string().refine(async (val) => val.length <= 8);\n\nawait schema.safeParseAsync(\"hello\");\n// => { success: true; data: \"hello\" }\n```\n\n### Inferring types\n\nZod infers a static type from your schema definitions. You can extract this type with the `z.infer<>` utility and use it however you like.\n\n```ts\nconst Player = z.object({\n  username: z.string(),\n  xp: z.number(),\n});\n\n// extract the inferred type\ntype Player = z.infer<typeof Player>;\n\n// use it in your code\nconst player: Player = { username: \"billie\", xp: 100 };\n```\n\nIn some cases, the input & output types of a schema can diverge. For instance, the `.transform()` API can convert the input from one type to another. In these cases, you can extract the input and output types independently:\n\n```ts\nconst mySchema = z.string().transform((val) => val.length);\n\ntype MySchemaIn = z.input<typeof mySchema>;\n// => string\n\ntype MySchemaOut = z.output<typeof mySchema>; // equivalent to z.infer<typeof mySchema>\n// number\n```\n","publish_time":1777671003830,"_cnpm_publish_time":1777671003830,"dist-tags":{"alpha":"3.25.68-alpha.11","beta":"4.1.13-beta.0","canary":"4.5.0-canary.20260828T171753","latest":"4.6.7","next":"3.25.0-beta.20250519T094321"}}