Skip to content

json-to-zod 1.1.2

Install from the command line:
Learn more about npm packages
$ npm install @spaceo/json-to-zod@1.1.2
Install via package.json:
"@spaceo/json-to-zod": "1.1.2"

About this version

Json-to-Zod

Summary

A very simple CLI tool to convert JSON objects or files into zod schemas.

Usage

CLI

json-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]

Programmatic

import { jsonToZod } from "json-to-zod"

const myObject = {
    hello: "hi"
}

const result = jsonToZod(myObject)

console.log(result)

Expected output:

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

Overriding zod values

Since zod can be more specific about the primitives sometime you want to be more precise.

Eg. if an string has been parsed to:

z.string();

But you know it is a date and therefor should be called:

z.string().date();

Then you can create a configuration file called: .jtzrc.yml and define schema overrides there.

Take a look at the .jtzrc.yml.example file.

Details


Assets

  • json-to-zod-1.1.2.tgz

Download activity

  • Total downloads 0
  • Last 30 days 0
  • Last week 0
  • Today 0

Recent versions

View all