Start a project

Tool 50 of 100 · Data

JSON to TypeScript

Paste an API response and get clean TypeScript interfaces and a Zod schema, with optional keys and union types worked out from every item.

JSON to TypeScript at a glanceIllustration: 1, API JSON; 2, processed in your browser; 3, Types + Zod.JSON to TypeScript{ }1API JSON</>3Types + Zod2In yourbrowser
1 API JSON 2 processed on your device 3 Types + Zod

JSON to TypeScript

Sample JSON

Paste a real response: the more items in each array, the better the optional keys and unions.

Options

Keys that appear in only some objects become optional. Different value types become unions, and identical shapes share one name.

Types

TypeScript
Zod schema (runtime validation)

01

What it does

Infers TypeScript interfaces and a Zod schema from sample JSON, merging array items, optional keys and unions.

  • Interfaces or type aliases
  • Array items merged into one shape
  • Keys missing from some items become optional
  • Mixed values become unions; null handled

02

Private by design

Everything happens in your browser. Nothing you type, paste or upload is sent anywhere, and it keeps working offline once the page has loaded.

03

What you get

TypeScript types and a Zod schema, with a Copy and a Download button on every result.

  • TypeScript
  • Zod
  • JSON

Why it matters

Typing an API response by hand is slow and error-prone, and the first time a field turns out to be null in production the types were wrong. Generating them from real responses is faster and more accurate.

This converter looks at every item in every array, so a key that only appears sometimes becomes optional and a value that is sometimes a string and sometimes a number becomes a union. Identical shapes share one interface, and a Zod schema is written alongside so you can check the data at runtime too.

How it works

  1. InputA JSON response or file
  2. In your browserEvery item compared to find optional and null fields
  3. OutputTypeScript interfaces, type aliases or Zod schemas

Where it fits in a designer's workflow

  1. Plan
  2. Design
  3. Build
  4. Test
  5. Launch
Typing an API before writing the code that calls it.

By the numbers

The sample JSON and the types the tool writes from itSample JSON (indented): 854 bytes; TypeScript interfaces: 422 bytes; Zod schemas: 832 bytesSample JSON (indented)854 bytesTypeScript interfaces422 bytesZod schemas832 bytes
Measured from this tool's output for its sample API response: 4 interfaces, with optional fields and null unions spotted by comparing every item in each array. Types cost nothing at run time; Zod schemas also check the data while the app runs. Source: TypeScript: object types.
Show the numbers as a table
OutputBytes
Sample JSON (indented)854
TypeScript interfaces422
Zod schemas832

How to use it

  1. Paste one or more sample responses as JSON.
  2. Name the root type and choose interfaces or type aliases.
  3. Check the optional keys and unions.
  4. Download or copy the TypeScript and the Zod schema.

FAQ

Why is a key marked optional?

Because at least one object in an array didn't have it. Paste more examples if that's wrong.

How are nulls typed?

As a union with null (string | null). If a key is always null, it becomes null; give a better sample to get the real type.

Why use Zod as well?

TypeScript types vanish at runtime. Zod checks that the data really matches, which matters for anything coming from an API.

Are dates detected?

No. ISO 8601 dates stay string, because JSON has no date type. Use z.string().datetime() in the Zod schema if you want them checked.

Work with me

Want a site that gets these right?

I build fast, accessible websites and web apps that pass these checks from day one. Tell me about your project and I'll reply personally with honest next steps.

All developer tools · Back to leej.uk