API Toolkit

Schema Codegen Desk

All tools

Get a runtime validator and its TypeScript type from data you already have.

How it works

Four simple steps

1

Paste JSON, Schema, or OpenAPI

Samples, JSON Schema, and components.schemas are auto-detected.

2

Choose Zod, TypeBox, or Valibot

Pick the runtime validator library your project uses.

3

Generate TypeScript

Copy a ready module with inferred types.

4

Drop into your repo

Review enums and .strict() options before shipping.

Schema Codegen Desk

About Schema Codegen Desk

Your frontend trusts whatever the API returns, and a renamed field just shipped a blank dashboard to production. Runtime validation is the fix, but typing out a Zod schema for a thirty-field response by hand is slow and easy to get wrong.

Paste JSON and the desk works out what it is. An object with openapi or swagger at the top is read as an OpenAPI document. One with $schema, properties, type or $ref is treated as JSON Schema. Anything else is a sample, and a schema is inferred from it: integers versus decimals, arrays typed from their first item, and every key required with no extra keys allowed. Choose Zod, TypeBox or Valibot and an export name, then press Generate. The output is a TypeScript module that imports the library, exports the validator and exports the matching type via z.infer, Static or InferOutput.

Mind the detection rules. A sample that happens to have a top-level "type" field, such as an order event, is read as JSON Schema and produces the wrong result, so wrap it in another object or rename the field. With OpenAPI input only the first entry in components.schemas is converted, and its name replaces your export name. $ref links become bare identifiers in Zod and fall back to an any type in TypeBox and Valibot. Zod gets the most detail, including .email(), .url(), .int() and .strict(). For plain interfaces without a runtime library, try JSON to TypeScript, and to produce a JSON Schema to feed back in, use the JSON Schema generator.

Code generation is string building in this page, with no packages downloaded and nothing sent out.

Keyboard shortcut

Ctrl Enter - Run tool
FAQ

Frequently asked questions

See all FAQs

Answers for this tool. For site-wide help, open the FAQ hub.

When the input is a sample, every key present is marked required and extra keys are rejected, since one example cannot show which fields are optional. Add .optional() afterwards, or start from a JSON Schema with a trimmed required list.

No. Integer and number both map to v.number() in the Valibot output. Add an integer check with Valibot's pipe helpers if you need it.

Not currently. Only the first schema under components.schemas is converted. To get another one, paste that schema on its own as JSON Schema.

View more FAQs

Related tools

View all

Webhook HMAC Signer

Sign and verify GitHub, Stripe, and Slack webhook signatures locally.

Open

Webhook Replay Diff Lab

Compare webhook payload timelines, re-check HMAC digests, and spot idempotency gaps locally.

Open

JSONPath Playground

Query JSON with JSONPath and JMESPath-style paths side by side.

Open

GraphQL Studio

Format, validate, and cost-estimate GraphQL documents with cURL export.

Open

Explore 321 free tools

Everything you need as a developer, marketer or creator - in one beautiful place.

Browse all tools