n8n/packages/@n8n/json-schema-to-zod
github-actions[bot] 247bcc16c8
🚀 Release 1.65.0 (#11386)
Co-authored-by: cstuncsik <5410822+cstuncsik@users.noreply.github.com>
2024-10-24 12:29:51 +02:00
..
src
test
.eslintrc.js
.gitignore
.npmignore
jest.config.js
LICENSE
package.json 🚀 Release 1.65.0 (#11386) 2024-10-24 12:29:51 +02:00
postcjs.js
postesm.js
README.md
tsconfig.cjs.json
tsconfig.esm.json
tsconfig.json
tsconfig.types.json

Json-Schema-to-Zod

A package to convert JSON schema (draft 4+) objects into Zod schemas in the form of Zod objects at runtime.

Installation

npm install @n8n/json-schema-to-zod

Simple example

import { jsonSchemaToZod } from "json-schema-to-zod";

const jsonSchema = {
  type: "object",
  properties: {
    hello: {
      type: "string",
    },
  },
};

const zodSchema = jsonSchemaToZod(myObject);

Overriding a parser

You can pass a function to the overrideParser option, which represents a function that receives the current schema node and the reference object, and should return a zod object when it wants to replace a default output. If the default output should be used for the node just return undefined.

Acknowledgements

This is a fork of json-schema-to-zod.