{"id":29351842,"url":"https://github.com/hideya/json-schema-to-zod","last_synced_at":"2026-01-20T17:27:13.302Z","repository":{"id":300723287,"uuid":"1006914791","full_name":"hideya/json-schema-to-zod","owner":"hideya","description":null,"archived":false,"fork":false,"pushed_at":"2025-06-23T09:18:46.000Z","size":25,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-06-23T09:23:36.136Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hideya.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-06-23T07:26:59.000Z","updated_at":"2025-06-23T07:27:03.000Z","dependencies_parsed_at":"2025-06-23T09:34:51.952Z","dependency_job_id":null,"html_url":"https://github.com/hideya/json-schema-to-zod","commit_stats":null,"previous_names":["hideya/json-schema-to-zod"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/hideya/json-schema-to-zod","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hideya%2Fjson-schema-to-zod","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hideya%2Fjson-schema-to-zod/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hideya%2Fjson-schema-to-zod/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hideya%2Fjson-schema-to-zod/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hideya","download_url":"https://codeload.github.com/hideya/json-schema-to-zod/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hideya%2Fjson-schema-to-zod/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264369069,"owners_count":23597330,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-07-09T00:08:08.053Z","updated_at":"2026-01-20T17:27:13.253Z","avatar_url":"https://github.com/hideya.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# Json-Schema-to-Zod\n\nA package to convert JSON schema (draft 4+) objects into Zod schemas in the form of Zod objects at runtime.\n\nA fork of [@n8n/json-schema-to-zod](https://github.com/n8n-io/n8n/tree/master/packages/%40n8n/json-schema-to-zod)\nwith improved ESM module compatibility.  \nThe src files are of Jun 21, 2025 (version 1.3.0, commit hash: `351db43`).\n\n## Installation\n\n```bash\nnpm install @h1deya/json-schema-to-zod\n```\n\n## Usage\n\n```javascript\nimport { jsonSchemaToZod } from '@h1deya/json-schema-to-zod';\nimport { z } from 'zod';\n\nconst schema = {\n  type: 'object',\n  properties: {\n    name: { type: 'string' },\n    age: { type: 'number' }\n  },\n  required: ['name']\n};\n\nconst zodSchema = jsonSchemaToZod(schema);\n\n// Validate data\nconst validData = { name: 'John', age: 30 };\nzodSchema.parse(validData); // Works!\n\nconst invalidData = { age: 30 };\ntry {\n  zodSchema.parse(invalidData);\n} catch (error) {\n  console.error(error); // Validation error: name is required\n}\n```\n\n## The Problem This Fork Solves\n\nWhen using the original `@n8n/json-schema-to-zod` package in an ESM environment (projects with `\"type\": \"module\"` in package.json), you might encounter this error:\n\n```\nError [ERR_MODULE_NOT_FOUND]: Cannot find module '.../parse-schema' imported from '.../json-schema-to-zod.js'\n```\n\nThis happens because:\n1. Node.js requires file extensions (like `.js`) in ESM import paths\n2. The original package's TypeScript source doesn't include these extensions\n3. When compiled for ESM, this creates broken imports\n\n## How This Fork Fixes It\n\nThis fork fixes the issue through a specialized build process that:\n1. Temporarily adds `.js` extensions to all imports in the TypeScript source\n2. Compiles the modified source to ESM\n3. Restores the original source code afterward\n\nThis approach:\n- Preserves the original source code (making future upstream syncs easier)\n- Produces ESM-compatible output that works in modern Node.js environments\n- Maintains full functionality and API compatibility\n\n### Additional Fix: CommonJS Require Removal\n\nA leftover CommonJS `require()` usage was found in `src/parsers/parse-nullable.ts`\nand was replaced with an ESM `import`:\n\n```typescript\n--- a/src/parsers/parse-nullable.ts\n+++ b/src/parsers/parse-nullable.ts\n@@ -1,9 +1,9 @@\n import { z } from 'zod';\n \n import type { JsonSchemaObject } from '../types';\n+import { parseSchema } from './parse-schema';\n \n export const parseNullable = (jsonSchema: JsonSchemaObject \u0026 { nullable: true }, refs: any) =\u003e {\n-       const { parseSchema } = require('./parse-schema');\n```\n\n## Source \u0026 Maintenance\n\nThis package is based on the original code from:\n- **Repository**: [n8n](https://github.com/n8n-io/n8n)\n- **Commit Hash**: `351db43` (Jun 21, 2025)\n- **Source Path**: [`packages/@n8n/json-schema-to-zod`](https://github.com/n8n-io/n8n/tree/master/packages/%40n8n/json-schema-to-zod)\n\nTo update with upstream changes:\n1. Update the source files in the `src` directory\n2. Run `npm run build`\n3. Test with `npm test`\n\n## Credits\n\nOriginal package created by Stefan Terdell and the n8n team.\n\nThis fork maintains the original ISC license and acknowledges all original contributors.\n\n## License\n\nISC License\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhideya%2Fjson-schema-to-zod","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhideya%2Fjson-schema-to-zod","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhideya%2Fjson-schema-to-zod/lists"}