raflymln/zod-key-parser(opens in a new tab)
Language: TypeScript
Parse your Zod schema into keys or Prisma ORM select format
- stars
- 25
- watchers
- 1
- forks
- 1
- open issues
- 5
- Last updated
- 04/03/2026
Language: TypeScript
Parse your Zod schema into keys or Prisma ORM select format
All bugs related to peer dependency, fail to parsing, and other bugs has been fixed in latest version
If you still have any problem, please make an issue in the GitHub repository
- Fix
keysissue withZodPipe- Migrated to Zod v4: All parsing and schema features now require Zod v4. Older Zod versions are supported on v1.
Parse your Zod schema into keys or ORM select format
import { parseZodSchema } from "zod-key-parser"; const schema = z.object({ a: z.boolean(), b: z.string(), c: z.string(), d: z.string(), e: z.string(), f: z.string(), g: z.string(), h: z.array( z.object({ ha: z.number(), hb: z.string(), hc: z.boolean(), hd: z.string(), }) ), i: z.object({ ia: z.number(), }), });
// schema.keys { "a": "a", "b": "b", "c": "c", "d": "d", "e": "e", "f": "f", "g": "g", "h": (index: number) => { "ha": `h.${index}.ha`, "hb": `h.${index}.hb`, "hc": `h.${index}.hc`, "hd": `h.${index}.hd`, }, "i": { "ia": "i.ia" } }
So that you can use it on your form like this:
<input name={schema.keys.a} type="string" ... />
// schema.selectKeys { "a": true, "b": true, "c": true, "d": true, "e": true, "f": true, "g": true, "h": { "select": { "ha": true, "hb": true, "hc": true, "hd": true } }, "i": { "select": { "ia": true } } }
So that you can use it on your ORM like this
const something = await orm.table.findUnique({ where: ..., select: schema.selectKeys })
There's 2 function, formatObject and formatFormData() that you can use
Use it to format object to keys format
const inputData = { formkey1: "something", formkey2: "something", "formkey3.a": "something", "formkey3.b": "something", "formkey5.c": "something", "formarray.0.a": "something", "formarray.1.a": "something", "formarray.1.ab": "something", "formarray.2.c.d.0.a": "true", "formarray.2.c.d.1.a": "true", }; const formattedData = formatObject(inputData);
// formattedData { "formkey1": "something", "formkey2": "something", "formkey3": { "a": "something", "b": "something" }, "formkey5": { "c": "something" }, "formarray": [ { "a": "something" }, { "a": "something", "ab": "something" }, { "c": { "d": [ { "a": true }, { "a": true } ] } } ] }
Use it to format data from form action directly, especially for React/Next.js user who use server action
It also use
formatObject()under the hood
const formAction = (formData: FormData) => { const parsed = schema.safeParse(formatFormData(formData)); if (!parsed.success) { ... } } return ( <form action={formAction}> <input name={schema.keys.a} /> <input name={schema.keys.b} /> </form> )
z.string() it wont parse anything since it doesn't have a keyFeel free to reach me at me@raflymaulana.me or just make a GitHub issue at this repository.