{"_id":"@adddog/zod-to-json-schema","_rev":"3-7d56ce4cd0aae52a71674bdd08f2982e","name":"@adddog/zod-to-json-schema","dist-tags":{"latest":"0.0.7"},"versions":{"0.0.1":{"name":"@adddog/zod-to-json-schema","version":"0.0.1","keywords":["zod","json-schema","schema","validation","typescript","converter","zod-v4"],"author":{"name":"Sam Elie","email":"sam@add.dog"},"license":"MIT","_id":"@adddog/zod-to-json-schema@0.0.1","maintainers":[{"name":"selie","email":"samradelie@gmail.com"}],"bin":{"zod-to-json-schema":"dist/cli/index.mjs"},"dist":{"shasum":"23b20928a2db8fdf70a58ac4b9f0295725dfc9cc","tarball":"https://registry.npmjs.org/@adddog/zod-to-json-schema/-/zod-to-json-schema-0.0.1.tgz","fileCount":10,"integrity":"sha512-N1+B3qPf/DdFeGbRCo94wChfTIZK/AhlB5OKPPXDVU7CUGTe3zFHIJN+qH4bwkgaV0BvvVxwdFHqlazwGR2slQ==","signatures":[{"sig":"MEUCIQCN762s7epo+qfJMdpGtLpwuD6x23WsMqy/h86NNir9QgIgFEUNrd8LvOBHv32rj4WAVCeIfWPefexC+qXf79u/S9I=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":22253},"main":"./dist/index.mjs","type":"module","_from":"file:adddog-zod-to-json-schema-0.0.1.tgz","types":"./dist/index.d.ts","module":"./dist/index.mjs","engines":{"npm":">= 11","node":">= 22","pnpm":">= 10"},"exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.mjs"}},"private":false,"scripts":{"dev":"tsx src/index.ts","knip":"knip","lint":"eslint .","test":"vitest run","build":"unbuild","types":"tsc -p tsconfig.typecheck.json","release":"bumpp","lint:fix":"eslint --fix ."},"_npmUser":{"name":"selie","email":"samradelie@gmail.com"},"_resolved":"/private/var/folders/rp/3hs8d62d09x33sqq4jxfx8th0000gn/T/c6142fbc26ef8aebbe92596eca176f75/adddog-zod-to-json-schema-0.0.1.tgz","_integrity":"sha512-N1+B3qPf/DdFeGbRCo94wChfTIZK/AhlB5OKPPXDVU7CUGTe3zFHIJN+qH4bwkgaV0BvvVxwdFHqlazwGR2slQ==","_npmVersion":"11.4.2","description":"Convert Zod v4 schemas to JSON Schema Draft 7","directories":{},"_nodeVersion":"24.4.0","dependencies":{"zod":"^4.1.12","commander":"^12.1.0"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"tsx":"^4.20.6","bumpp":"^10.3.1","eslint":"^9.37.0","vitest":"^3.2.4","unbuild":"^3.6.1","typescript":"^5.9.3","@rad/config":"0.0.0","@rad/eslint":"0.0.0","@types/node":"^22.18.10"},"_npmOperationalInternal":{"tmp":"tmp/zod-to-json-schema_0.0.1_1760220314135_0.6163495279570457","host":"s3://npm-registry-packages-npm-production"}},"0.0.6":{"name":"@adddog/zod-to-json-schema","version":"0.0.6","keywords":["zod","json-schema","schema","validation","typescript","converter","zod-v4"],"author":{"name":"Sam Elie","email":"sam@add.dog"},"license":"MIT","_id":"@adddog/zod-to-json-schema@0.0.6","maintainers":[{"name":"selie","email":"samradelie@gmail.com"}],"bin":{"zod-to-json-schema":"dist/cli/index.mjs"},"dist":{"shasum":"e0c26f1a229b78e2c9f77ec7461406e5558520c8","tarball":"https://registry.npmjs.org/@adddog/zod-to-json-schema/-/zod-to-json-schema-0.0.6.tgz","fileCount":10,"integrity":"sha512-eHgLfs1VK2gpe/593fG/SbttwuER2j8Pb3D516yapXuS80DFI7+8srfQgpEqPKsLcXoTg40kChE/0dzxT1HVpQ==","signatures":[{"sig":"MEUCIGSvsiQgWZCXoRlpife2xM5TldcyDXl1OB8Z8bbWhP15AiEA4fZECYHMTueSOsGVWwVa3yDnVTJIfCsszLIYj0fkrtA=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":26671},"main":"./dist/index.mjs","type":"module","_from":"file:adddog-zod-to-json-schema-0.0.6.tgz","types":"./dist/index.d.ts","engines":{"npm":">= 11","node":">= 22","pnpm":">= 10"},"exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.mjs"}},"private":false,"scripts":{"dev":"tsx src/index.ts","knip":"knip","lint":"eslint .","test":"echo '⚠️⚠️⚠️no test vitest --watch=false'","build":"unbuild","types":"tsc -p tsconfig.typecheck.json","release":"bumpp --yes --no-push --no-tag --release patch","lint:fix":"eslint --fix .","version:patch":"npm version patch --no-git-tag-version"},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:a0b19553-5959-4d5a-b315-4873d717c595"}},"_resolved":"/home/runner/work/samelie-monorepo/samelie-monorepo/packages/zod-to-json-schema/adddog-zod-to-json-schema-0.0.6.tgz","_integrity":"sha512-eHgLfs1VK2gpe/593fG/SbttwuER2j8Pb3D516yapXuS80DFI7+8srfQgpEqPKsLcXoTg40kChE/0dzxT1HVpQ==","_npmVersion":"11.10.1","description":"Convert Zod v4 schemas to JSON Schema Draft 7","directories":{},"_nodeVersion":"24.4.0","dependencies":{"zod":"^4.3.6","commander":"^14.0.3"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"tsx":"^4.21.0","bumpp":"^10.4.1","eslint":"^10.0.2","vitest":"^4.0.18","unbuild":"^3.6.1","typescript":"^5.9.3","@types/node":"^25.3.0","@adddog/monorepo-consistency":"0.0.14"},"_npmOperationalInternal":{"tmp":"tmp/zod-to-json-schema_0.0.6_1771952482938_0.27762015848520205","host":"s3://npm-registry-packages-npm-production"}},"0.0.7":{"name":"@adddog/zod-to-json-schema","version":"0.0.7","description":"Convert Zod v4 schemas to JSON Schema Draft 7","type":"module","author":{"name":"Sam Elie","email":"sam@add.dog"},"license":"MIT","keywords":["zod","json-schema","schema","validation","typescript","converter","zod-v4"],"main":"./dist/index.mjs","types":"./dist/index.d.ts","bin":{"zod-to-json-schema":"dist/cli/index.mjs"},"exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.mjs"}},"dependencies":{"commander":"^14.0.3","zod":"^4.3.6"},"devDependencies":{"@types/node":"^25.3.0","bumpp":"^10.4.1","eslint":"^10.0.2","tsx":"^4.21.0","typescript":"^5.9.3","unbuild":"^3.6.1","vitest":"^4.0.18"},"publishConfig":{"access":"public"},"private":false,"engines":{"node":">= 22","pnpm":">= 10","npm":">= 11"},"scripts":{"build":"unbuild","lint":"eslint .","lint:fix":"eslint --fix .","release":"bumpp --yes --no-push --no-tag --release patch","types":"tsc -p tsconfig.typecheck.json","test":"echo '⚠️⚠️⚠️no test vitest --watch=false'","dev":"tsx src/index.ts","knip":"knip","version:patch":"npm version patch --no-git-tag-version"},"_id":"@adddog/zod-to-json-schema@0.0.7","_integrity":"sha512-0I+sr2KQN8ztrrhsL8oQF25RedPM6HxgFSm47wzgalMBJO3RFW7DSVBIPOXydc0pHyKJ/Bk5zFjfyK0IAbvtnw==","_resolved":"/home/runner/work/samelie-monorepo/samelie-monorepo/packages/zod-to-json-schema/adddog-zod-to-json-schema-0.0.7.tgz","_from":"file:adddog-zod-to-json-schema-0.0.7.tgz","_nodeVersion":"24.4.0","_npmVersion":"11.10.1","dist":{"integrity":"sha512-0I+sr2KQN8ztrrhsL8oQF25RedPM6HxgFSm47wzgalMBJO3RFW7DSVBIPOXydc0pHyKJ/Bk5zFjfyK0IAbvtnw==","shasum":"a529bd802cc521f1dada200d94c1cb3784b07eac","tarball":"https://registry.npmjs.org/@adddog/zod-to-json-schema/-/zod-to-json-schema-0.0.7.tgz","fileCount":10,"unpackedSize":26625,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIBDoGMmLCIBetN1qfLDqG04sLfjsKV6mQFvvusc2Ue9WAiEAq9DwpRchabgnqQ8373GJeh+FNIce4Gxci7Cp51m8csc="}]},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:a0b19553-5959-4d5a-b315-4873d717c595"}},"directories":{},"maintainers":[{"name":"selie","email":"samradelie@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/zod-to-json-schema_0.0.7_1771954520141_0.1500182200310869"},"_hasShrinkwrap":false}},"time":{"created":"2025-10-11T22:05:14.024Z","modified":"2026-02-24T17:35:20.422Z","0.0.1":"2025-10-11T22:05:14.364Z","0.0.6":"2026-02-24T17:01:23.084Z","0.0.7":"2026-02-24T17:35:20.291Z"},"author":{"name":"Sam Elie","email":"sam@add.dog"},"license":"MIT","keywords":["zod","json-schema","schema","validation","typescript","converter","zod-v4"],"description":"Convert Zod v4 schemas to JSON Schema Draft 7","maintainers":[{"name":"selie","email":"samradelie@gmail.com"}],"readme":"# @adddog/zod-to-json-schema\n\nConvert [Zod v4](https://zod.dev) schemas to [JSON Schema Draft 7](https://json-schema.org/draft-07/json-schema-release-notes.html).\n\n**A lightweight wrapper around Zod's built-in `toJSONSchema` with a simpler API and CLI tool.**\n\n## Features\n\n- ✅ **Uses Zod's Native Implementation** - Wraps Zod v4's built-in JSON Schema generator\n- 🎯 **Simpler API** - Easy-to-use options for common use cases\n- 🚀 **CLI Included** - Convert schemas from files with a simple command\n- 📦 **Tiny Bundle** - Only 11 kB total (leverages Zod's implementation)\n- 🔧 **Type-Safe** - Full TypeScript support\n- 🧪 **Well-Tested** - 22 passing tests\n\n## Installation\n\n```bash\npnpm add @adddog/zod-to-json-schema\n# or\nnpm install @adddog/zod-to-json-schema\n# or\nyarn add @adddog/zod-to-json-schema\n```\n\n## Usage\n\n### Programmatic API\n\n```typescript\nimport * as z from \"zod/v4\";\nimport { zodToJsonSchema } from \"@adddog/zod-to-json-schema\";\n\n// Define your Zod schema\nconst userSchema = z.object({\n  name: z.string(),\n  age: z.number().int().positive(),\n  email: z.string().email(),\n  role: z.enum([\"admin\", \"user\", \"guest\"]),\n  settings: z.object({\n    theme: z.enum([\"light\", \"dark\"]),\n    notifications: z.boolean(),\n  }).optional(),\n});\n\n// Convert to JSON Schema\nconst jsonSchema = zodToJsonSchema(userSchema, {\n  name: \"User\",\n  $schemaUrl: true,\n});\n\nconsole.log(JSON.stringify(jsonSchema, null, 2));\n```\n\nOutput:\n\n```json\n{\n  \"$schema\": \"http://json-schema.org/draft-07/schema#\",\n  \"title\": \"User\",\n  \"type\": \"object\",\n  \"properties\": {\n    \"name\": { \"type\": \"string\" },\n    \"age\": { \"type\": \"number\" },\n    \"email\": { \"type\": \"string\", \"format\": \"email\" },\n    \"role\": { \"enum\": [\"admin\", \"user\", \"guest\"] },\n    \"settings\": {\n      \"anyOf\": [\n        {\n          \"type\": \"object\",\n          \"properties\": {\n            \"theme\": { \"enum\": [\"light\", \"dark\"] },\n            \"notifications\": { \"type\": \"boolean\" }\n          },\n          \"required\": [\"theme\", \"notifications\"]\n        },\n        { \"not\": {} }\n      ]\n    }\n  },\n  \"required\": [\"name\", \"age\", \"email\", \"role\"]\n}\n```\n\n### CLI Usage\n\n```bash\n# Convert a schema file\nzod-to-json-schema convert ./schemas/user.schema.ts --output ./schemas/user.json --pretty\n\n# With options\nzod-to-json-schema convert ./schemas/user.schema.ts \\\n  --name \"User Schema\" \\\n  --export \"userSchema\" \\\n  --pretty \\\n  --strict\n```\n\n#### CLI Options\n\n- `-o, --output <file>` - Output file path (default: `<input>.schema.json`)\n- `-n, --name <name>` - Schema name/title\n- `-e, --export <name>` - Named export to convert (default: 'default')\n- `--no-schema-url` - Don't include $schema URL\n- `--strict` - Strict mode - fail on unsupported features\n- `--pretty` - Pretty print JSON output\n- `--ref-strategy <strategy>` - Reference strategy: root, relative, none (default: root)\n\n## API\n\n### `zodToJsonSchema(schema, options?)`\n\nConvert a Zod schema to JSON Schema.\n\n#### Parameters\n\n- `schema` - A Zod schema instance\n- `options` - Optional configuration object\n\n#### Options\n\n```typescript\ntype ConverterOptions = {\n  // Name for the root schema (added as \"title\")\n  name?: string;\n\n  // Base path for $ref resolution (default: [\"#\"])\n  basePath?: string[];\n\n  // Definition path segment (default: \"$defs\")\n  definitionPath?: string;\n\n  // Reference strategy (default: \"root\")\n  $refStrategy?: \"root\" | \"relative\" | \"none\";\n\n  // Target JSON Schema version (default: \"jsonSchema7\")\n  target?: \"jsonSchema7\" | \"jsonSchema2019-09\" | \"openApi3\";\n\n  // Whether to include the $schema property (default: false)\n  $schemaUrl?: boolean;\n\n  // Custom error messages\n  errorMessages?: boolean;\n\n  // Strict mode - fail on unsupported features (default: false)\n  strict?: boolean;\n\n  // Mark all properties as readonly\n  markdownDescription?: boolean;\n\n  // Definitions to include in the schema\n  definitions?: Record<string, JsonSchema7>;\n};\n```\n\n## Supported Zod Types\n\n### Fully Supported (with JSON Schema representation)\n\n**Primitives:**\n- ✅ `z.string()` - with formats (email, url, uuid, etc.) and constraints (min, max, regex)\n- ✅ `z.number()` - with constraints (min, max, int, positive, etc.)\n- ✅ `z.boolean()`\n- ✅ `z.null()`\n- ✅ `z.any()`\n- ✅ `z.unknown()`\n- ✅ `z.never()`\n- ✅ `z.literal()`\n- ✅ `z.enum()`\n- ✅ `z.nativeEnum()`\n\n**Complex Types:**\n- ✅ `z.array()` - with min/max items\n- ✅ `z.object()` - with nested properties and required fields\n- ✅ `z.record()` - with property name validation\n- ✅ `z.tuple()` - with prefix items and rest elements\n\n**Wrappers:**\n- ✅ `z.optional()`\n- ✅ `z.nullable()`\n- ✅ `z.default()` - includes default value in schema\n- ✅ `z.readonly()` - marks as readOnly\n- ✅ `z.catch()` - includes default/fallback value\n- ✅ `z.branded()` - transparent (uses underlying type)\n- ✅ `z.pipeline()` - uses input or output type based on `io` option\n\n**Unions & Intersections:**\n- ✅ `z.union()` - becomes `anyOf`\n- ✅ `z.discriminatedUnion()` - optimized union representation\n- ✅ `z.intersection()` - becomes `allOf`\n\n### Limited Support (unrepresentable in JSON)\n\nThese types become `{}` (any) in non-strict mode, or throw errors in strict mode:\n\n- ⚠️ `z.bigint()` - No native JSON representation\n- ⚠️ `z.date()` - No native JSON representation (use `z.string().datetime()` instead)\n- ⚠️ `z.symbol()` - No native JSON representation\n- ⚠️ `z.undefined()` - No native JSON representation (use `z.optional()` instead)\n- ⚠️ `z.void()` - No native JSON representation\n- ⚠️ `z.map()` - No native JSON representation\n- ⚠️ `z.set()` - No native JSON representation (use `z.array().unique()` instead)\n- ⚠️ `z.function()` - Functions cannot be serialized to JSON\n- ⚠️ `z.custom()` - Custom validators cannot be represented\n\n**Tip:** Set `strict: true` in options to throw errors for unrepresentable types instead of converting them to `{}`.\n\n## Examples\n\n### Basic Types\n\n```typescript\nimport * as z from \"zod/v4\";\nimport { zodToJsonSchema } from \"@adddog/zod-to-json-schema\";\n\n// String\nzodToJsonSchema(z.string());\n// => { \"type\": \"string\" }\n\n// Number with constraints\nzodToJsonSchema(z.number().min(0).max(100));\n// => { \"type\": \"number\", \"minimum\": 0, \"maximum\": 100 }\n\n// Enum\nzodToJsonSchema(z.enum([\"red\", \"green\", \"blue\"]));\n// => { \"enum\": [\"red\", \"green\", \"blue\"] }\n\n// Literal\nzodToJsonSchema(z.literal(\"hello\"));\n// => { \"const\": \"hello\" }\n```\n\n### Complex Schemas\n\n```typescript\n// Array\nzodToJsonSchema(z.array(z.string()));\n// => { \"type\": \"array\", \"items\": { \"type\": \"string\" } }\n\n// Object with nested properties\nconst schema = z.object({\n  user: z.object({\n    id: z.string().uuid(),\n    name: z.string(),\n    email: z.string().email(),\n  }),\n  posts: z.array(\n    z.object({\n      title: z.string(),\n      content: z.string(),\n    })\n  ),\n});\n\nzodToJsonSchema(schema);\n```\n\n### Union Types\n\n```typescript\n// Simple union\nzodToJsonSchema(z.union([z.string(), z.number()]));\n// => { \"anyOf\": [{ \"type\": \"string\" }, { \"type\": \"number\" }] }\n\n// Nullable\nzodToJsonSchema(z.string().nullable());\n// => { \"anyOf\": [{ \"type\": \"string\" }, { \"type\": \"null\" }] }\n\n// Optional\nzodToJsonSchema(z.string().optional());\n// => { \"anyOf\": [{ \"type\": \"string\" }, { \"not\": {} }] }\n```\n\n## Architecture\n\nThis library is a **lightweight wrapper** around Zod v4's native `toJSONSchema` implementation:\n\n```\nsrc/\n├── types.ts              # Type definitions\n├── converter.ts          # Wrapper around Zod's toJSONSchema\n├── cli/\n│   └── index.ts         # CLI implementation\n└── converter.test.ts     # Test suite\n```\n\n### Why This Wrapper?\n\nWhile Zod v4 has excellent built-in JSON Schema support, this library provides:\n\n1. **Simpler API** - Easy-to-understand options instead of Zod's lower-level API\n2. **CLI Tool** - Convert schemas from files without writing code\n3. **Consistent Defaults** - Sensible defaults for common use cases\n4. **Better Documentation** - Clear examples and usage patterns\n\n## Development\n\n```bash\n# Install dependencies\npnpm install\n\n# Build\npnpm build\n\n# Test\npnpm test\n\n# Type check\npnpm types\n\n# Lint\npnpm lint\n\n# Run all checks (same as prepublish)\npnpm run prepublishOnly\n```\n\n### Publishing\n\nThe package includes automated release tooling with `bumpp` and a `prepublishOnly` script:\n\n**Full Release Workflow:**\n\n```bash\n# 1. Bump version (creates commit and tag)\npnpm run release           # Interactive version selection\npnpm run release -- --patch  # 0.0.1 → 0.0.2\npnpm run release -- --minor  # 0.0.1 → 0.1.0\npnpm run release -- --major  # 0.0.1 → 1.0.0\n\n# 2. Publish to npm (prepublishOnly runs automatically)\npnpm publish\n```\n\n**What `prepublishOnly` does:**\n\n```bash\npnpm run prepublishOnly\n# Runs: test → lint → types → build\n```\n\nThis ensures all checks pass before the package is published to npm. The script runs automatically when you execute `pnpm publish`.\n\n**Manual verification (optional):**\n\n```bash\n# Run all checks without publishing\npnpm run prepublishOnly\n```\n\n## License\n\nMIT © Sam Elie\n\n## Related\n\n- [Zod](https://github.com/colinhacks/zod) - TypeScript-first schema validation\n- [JSON Schema](https://json-schema.org/) - JSON Schema specification\n- [zod-to-json-schema](https://github.com/StefanTerdell/zod-to-json-schema) - Original Zod v3 converter (inspiration)\n","readmeFilename":"README.md"}