一覧へ戻る
rsinohara/json-to-zod(新しいタブで開きます)
主要言語: TypeScript
Converts JSON objects or file to simple Zod schemas
- star 数
- 71
- watcher 数
- 3
- fork 数
- 11
- issue 数
- 5
- 最終更新
- 2025/03/12
主要言語: TypeScript
Converts JSON objects or file to simple Zod schemas
A very simple CLI tool to convert JSON objects or files into zod schemas.
json-to-zod -s myJson.json -t mySchema.ts
Options:
import { jsonToZod } from "json-to-zod" const myObject = { hello: "hi" } const result = jsonToZod(myObject) console.log(result)
const schema = z.object({hello: z.string()});
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.
You can use the convertTuples option to handle tuples correctly.
import { jsonToZod } from "json-to-zod" const myTuple = [1, 'some string'] const result = jsonToZod(myTuple, "schema", false, true) console.log(result)
const schema = z.tuple([z.number(), z.string()]);