Generate TypeScript types from a JSON response

Turn a real API response into interfaces, with array shapes merged so fields that are missing from some records come out optional.

Open this example in JSON to TypeScript

Open the tool, then paste the sample input below. Everything runs locally in your browser.

Open this example in JSON to TypeScript →

The problem

Hand-writing types for an undocumented API means typing the first response you happened to see. The second record has an extra field, or a number where the first had a string, and the type quietly stops describing reality.

Sample input

API response
{"id":7,"sessions":[{"ip":"10.0.0.4"},{"ip":"10.0.0.9","agent":"curl/8.4"}]}

Expected output

Generated TypeScript
export interface Session {
  ip: string;
  agent?: string;
}

export interface Root {
  id: number;
  sessions: Session[];
}

How to do it

  1. Paste a real response - ideally one with several array elements.
  2. Choose interface or type alias, and whether declarations are exported.
  3. Check which fields came out optional; those are the ones missing from some records.
  4. Rename Root to something meaningful for your domain.
  5. Copy or download the .ts file into your project.

Common mistakes

  • Generating from a single array element, so genuinely optional fields look required.
  • Treating a null field as permanently null instead of nullable.
  • Assuming the generated types validate anything at runtime - they do not.
  • Committing the Root name instead of the domain name the codebase uses.

Related tools

FAQ

How do I generate TypeScript from a JSON response?

Paste the JSON sample - the interfaces are generated as you type, with nested objects extracted into their own named interfaces.

Why is a field marked optional?

Because it is missing from at least one element of an array in your sample. That is the payload telling you the field is not guaranteed.

Do the generated types validate data at runtime?

No. TypeScript types are compile-time only. Mirror the shape in Zod, io-ts or a JSON Schema if you need runtime validation.

Is my payload uploaded?

No. Parsing and code generation run locally in your browser, which is why a production response is safe to paste.

This guide uses browser-local tooling. Avoid pasting production secrets unless you understand what the tool displays and shares.

Explore related tools

Continue with adjacent browser-based tools for the same workflow.

View JSON and API contract tools →

Generate TypeScript types from JSON: quick answer

Use this when integrating an API with no OpenAPI spec, typing a webhook payload, or checking whether published types still match a live response. Paste a sample with several array elements so optional fields are detected properly.

What to verify

Check which fields came out optional and whether that matches the API documentation, widen any field you know is nullable, and rename the root interface before committing it.

Recommended next steps