This package has been deprecated

Author message:

Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.

json-schema-to-zod-with-defaults
TypeScript icon, indicating that this package has built-in type declarations

0.2.1 • Public • Published

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]
  • --defaults [(options) include default values]

Programmatic

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

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

const result = jsonSchemaToZod(myObject);
console.log(result);

const zodSchema = parseSchema(myObject);
console.log(zodSchema);

Expected output:

import { z } from "zod";

export default z.object({ hello: z.string().optional() });

and

z.object({hello: z.string().optional()})

Package Sidebar

Install

npm i json-schema-to-zod-with-defaults

Weekly Downloads

1

Version

0.2.1

License

ISC

Unpacked Size

25.7 kB

Total Files

45

Last publish

Collaborators

  • lstrojny