Back to results
jbeoris/gemini-zod(opens in a new tab)
Language: TypeScript
- stars
- 52
- watchers
- 1
- forks
- 6
- open issues
- 3
- Last updated
- 02/13/2025
Language: TypeScript
Gemini AI Schema to Zod Adapter
gemini-zod is a lightweight library that provides seamless conversion between Gemini AI schemas and Zod schemas. This adapter allows you to easily integrate Gemini AI's schema definitions with Zod's powerful runtime type checking and validation capabilities.
npm install gemini-zod
import { toGeminiSchema } from 'gemini-zod'; import { z } from 'zod'; const zodSchema = z.object({ name: z.string(), age: z.number(), isStudent: z.boolean().optional(), }); const geminiSchema = toGeminiSchema(zodSchema); // Equivalent Gemini AI schema: // { // type: 'object', // properties: { // name: { type: 'string' }, // age: { type: 'number' }, // isStudent: { type: 'boolean', nullable: true }, // }, // required: ['name', 'age'], // }
import { toZodSchema } from 'gemini-zod'; import { z } from 'zod'; const geminiSchema = { type: 'object', properties: { name: { type: 'string' }, age: { type: 'number' }, isStudent: { type: 'boolean', nullable: true }, }, required: ['name', 'age'], }; const zodSchema = toZodSchema(geminiSchema); // Equivalent Zod schema: // z.object({ // name: z.string(), // age: z.number(), // isStudent: z.boolean().optional(), // })