Pular para o conteúdo
POST AI agent ready /v1/schema/json-to-zod

JSON to Zod API - Generate Zod Schemas from JSON Samples

Infers Zod constructors from the provided JSON: strings → z.string(), integers → z.number().int(), floats → z.number(), booleans → z.boolean(), arrays → z.array(...), nested objects → z.object({...}). Returns a const-declaration string you can paste into your codebase.

Parameters

objectrequired

JSON value to infer schema from.

string

Base name. The output const is named {name}Schema.

Code examples

curl -X POST https://api.botoi.com/v1/schema/json-to-zod \
  -H "Content-Type: application/json" \
  -d '{"json":{"id":42,"email":"ada@example.com","verified":true},"name":"User"}'

When to use this API

Scaffold runtime validation for API responses

After verifying the shape of a third-party API response, generate the Zod schema and drop it into your fetch wrapper. Parse-at-boundaries pattern catches upstream breaking changes early.

TRPC / Hono / Next.js API input schemas

Generate schemas for request payloads from real traffic samples. Wire them into your framework's input validation layer instead of writing them by hand.

Contract tests from fixtures

Store canonical JSON fixtures per endpoint. Generate Zod schemas from them and use in tests to detect schema drift when the production response changes.

Frequently asked questions

Which Zod version does the output target?
Zod 3.x API. The output uses z.object, z.array, z.string, z.number, z.boolean, z.null, z.unknown, and z.record, which all exist in both v3 and v4 with the same syntax.
Are integer versus float numbers distinguished?
Yes. Integer samples produce z.number().int(); samples with decimals produce z.number(). Adjust after generation if you need stricter rules like z.number().positive().
Does the output include refinements or optional fields?
No. The generator emits the base type per field. Add .optional(), .min(), .email(), or .refine() manually based on your domain rules.
How are nulls and empty arrays handled?
null → z.null(). Empty arrays → z.array(z.unknown()) since the element type cannot be inferred. Pass a non-empty array sample to get a specific element type.
Do I need to import z separately?
Yes. The output assumes z is already imported. Add `import { z } from "zod";` at the top of your file.

Get your API key

Free tier includes 5 requests per minute with no credit card required. Upgrade for higher limits.