schemaToJSONSchema
schemaToJSONSchema(
schema,options?):Record<string,unknown>
Defined in: gadgets/schema-to-json.ts:47
Convert a Zod schema to JSON Schema with description fallback.
If descriptions exist in schema._def but are missing from the generated JSON Schema (indicating a Zod instance mismatch), this function:
- Logs a warning recommending
import { z } from "llmist" - Extracts descriptions from _def and merges them into the JSON Schema
Parameters
Section titled “Parameters”schema
Section titled “schema”ZodType
Zod schema to convert
options?
Section titled “options?”Conversion options (target JSON Schema version)
target?
Section titled “target?”"draft-7" | "draft-2020-12"
Returns
Section titled “Returns”Record<string, unknown>
JSON Schema object with descriptions preserved
Example
Section titled “Example”import { schemaToJSONSchema } from './schema-to-json.js';import { z } from 'zod';
const schema = z.object({ name: z.string().describe('User name'),});
const jsonSchema = schemaToJSONSchema(schema);// { type: 'object', properties: { name: { type: 'string', description: 'User name' } } }