Skip to content
MyToolers

JSON to TypeScript & Zod Generator

Paste JSON and get TypeScript interfaces and a Zod schema, with nested types.

3 interfaces generated.

About this tool

Turn any JSON — an API response, a config file or a database export — into ready-to-use TypeScript interfaces and a matching Zod validation schema. Nested objects become their own named types, arrays of objects are merged so fields missing from some items become optional, and mixed values become unions. Copy the result straight into your project.

How to use it

  1. Paste your JSON, or edit the sample.
  2. Set the root type name and choose interface or type alias.
  3. Switch between the TypeScript and Zod tabs and copy the code.

Good to know

  • Nested objects get their own interface, named after their key (customer → Customer); array items use the singular (items → Item).
  • When an array holds several objects, a key that is missing from some of them is marked optional (gift?: boolean).
  • Values that differ between items become unions (number | string), and null values become null in TypeScript and .nullable() in Zod.
  • The Zod output declares child schemas before parents and adds a z.infer type for each, so it compiles as pasted (with zod installed).
  • Keys that aren't valid identifiers, such as delivery-zone, are quoted. Everything runs in your browser.

Why generate types from real JSON

Writing interfaces for an API by hand is slow and easy to get wrong — a field named phone_number in the docs might really arrive as phoneNumber, or a price might be a string. Generating types from an actual response gives you an accurate starting point, which you then refine: rename types, narrow a string to a union of known values, or mark a field optional.

Worked example

An order with a nested customer and a list of items produces three interfaces: Order, Customer and Item. Because only the second item has a gift field, it becomes gift?: boolean, and because note is null in the sample, it is typed as null — change it to string | null if you know notes can be text.

The Zod tab produces CustomerSchema and ItemSchema first, then OrderSchema that uses them, and exports type Order = z.infer<typeof OrderSchema>, so one schema gives you both runtime validation and the TypeScript type.

Tips for better results

Paste a response that includes every field you care about, ideally an array with several varied items so optional fields and unions are detected. Use a clear root name such as Order or ApiResponse. For dates, the generator sees strings; in Zod you can tighten them to z.string().datetime() or z.coerce.date().

Frequently asked questions

How do I convert JSON to a TypeScript interface?

Paste the JSON, give the root type a name and copy the generated interfaces. Each nested object becomes its own interface, so the result is easy to read and reuse.

What is Zod and why generate a schema?

Zod is a popular TypeScript library that checks data at runtime. TypeScript types disappear when your code runs, so a Zod schema is what actually rejects a malformed API response.

How are optional fields detected?

From the sample itself: in an array of objects, a key that appears in only some items is optional. A single object can't show which fields are optional, so tick “Make every field optional” if needed, or edit the output.

Is my JSON sent anywhere?

No. The types are generated in your browser, so API responses with customer data or tokens never leave your device.