Developer Tools

JSON to TypeScript and Zod Converter

Paste a JSON object, an API response or a config file and get clean TypeScript interfaces or a ready-to-use Zod schema as you type. Nested objects become their own named types, and keys that only appear in some items are marked optional. Everything runs in your browser, so your data never leaves your device.

JSON to TypeScript and Zod Converter

Free · No sign-up
Loading tool…

A free JSON to TypeScript converter

Typing an API response by hand is slow and easy to get wrong, especially when it's nested several levels deep. This JSON to TypeScript converter reads your data and writes the types for you: strings, numbers, booleans, arrays and nested objects, with each nested object as its own named interface so the result stays readable.

Names come from the keys. A user key becomes a User interface, and an items array becomes Item[]. Keys that aren't valid identifiers, such as first-name, are quoted automatically, and a JSON file whose root is an array produces a Root type for the array plus a type for its items. It's one of our free developer tools that run in your browser, with no sign-up and no limits.

Convert a JSON response to a TypeScript interface

The most common use is typing what an API sends back. Open your browser's Network tab, copy the response body, paste it here and you have an interface for fetch or axios in seconds. Paste a response that includes a few items rather than one, so the converter can spot which fields are optional.

Many API responses also carry an access token. If you need to see what's inside one, use our JWT decoder to read its claims and check when it expires, also without sending it anywhere.

Generate a Zod schema from JSON

TypeScript types disappear when your code runs, so they can't tell you whether an API actually returned what you expected. A Zod schema can. Switch to the Zod tab and this JSON to Zod converter gives you a schema for every object, plus a matching type created with z.infer, so the types and the runtime check never drift apart.

With format checks on, strings that all look like dates, emails or URLs get .datetime(), .date(), .email() or .url(), and whole numbers get .int(). Turn those options off if your real data is less consistent than your sample. The output works with Zod 3 and Zod 4.

Optional fields, nulls and mixed arrays

One sample is only a guess at the real shape of your data, so the converter looks at every item in an array before deciding. If a key is missing from some items, it's marked optional (name?: string, or .optional() in Zod). A value that's sometimes null becomes string | null, or .nullable() in Zod, and arrays that mix types get a union such as (number | string)[].

JSON to TypeScript type or interface?

For plain object shapes like API responses, the two are almost interchangeable. Interfaces are the common choice in many codebases and can be extended and merged; type aliases are needed for unions and some advanced patterns. Pick whichever your project already uses; the readonly and export options apply to both.

If an AI coding assistant writes much of your code, tell it which style you prefer once, in a rules file, instead of correcting it every time. Our CLAUDE.md generator builds that file for Claude Code, Cursor and Copilot, including rules like “validate API data with Zod”.

Messy JSON is fixed for you

Copied an object from JavaScript code or a config file? Comments, single quotes, unquoted keys and trailing commas are cleaned up automatically, and the tool tells you what it fixed. If the JSON is really broken, you'll see the line and column of the problem instead of a vague error.

Private by design

API responses often contain real names, emails or tokens. This converter is plain code running in your browser, with no server and no AI model, so nothing you paste is uploaded or stored. It even keeps working if you go offline after the page has loaded.

Frequently asked questions

How do I convert JSON to a TypeScript interface?

Paste your JSON into the box above. The TypeScript interfaces appear instantly on the right; copy them or download a .ts file. Nested objects become separate named interfaces.

How do I generate a Zod schema from JSON?

Paste your JSON and switch to the Zod schema tab. You get a schema for each object and a matching TypeScript type created with z.infer.

Does it work with Zod 4?

Yes. The generated schemas use methods available in both Zod 3 and Zod 4. Zod 4 also offers shorter forms such as z.email(), but the generated code runs unchanged.

How are optional fields detected?

When an array contains several objects, any key missing from some of them is marked optional. With a single object, every key is treated as required, so paste a few varied items for better results.

Should I use an interface or a type for JSON data?

Either works for plain object shapes. Interfaces can be extended and merged, while type aliases also handle unions. Use whatever style your project already follows.

Can it convert JSON to a TypeScript class?

No. It generates interfaces, type aliases and Zod schemas, which is what most projects use for JSON data. Classes are only needed when the data must carry methods.

Can it convert a JavaScript object, not strict JSON?

Yes. Comments, single quotes, unquoted keys and trailing commas are fixed automatically before conversion, and the tool lists what it changed.

Is my JSON uploaded anywhere?

No. The conversion runs entirely in your browser. Nothing is sent to a server or an AI model, so it's safe to paste real API responses.