taishi8117 / json-schema-to-zod

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Json-Schema-to-Zod

NPM Version

Summary

A very simple CLI tool to convert JSON schema (draft 4+) objects or files into Zod schemas. Uses Prettier for formatting for now.

Usage

Online

Paste your schemas here

CLI

json-schema-to-zod -s myJson.json -t mySchema.ts

Options:

  • --source/-s [source file name]
  • --target/-t [(optional) target file name]
  • --name/-n [(optional) schema name in output]
  • --deref/-d [(optional) deref schemas before parsing]

Programmatic

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

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

const result = jsonSchemaToZod(myObject);

console.log(result);

Expected output:

const schema = z.object({hello: z.string()});

About

License:ISC License


Languages

Language:TypeScript 76.8%Language:JavaScript 23.2%