JSON to TypeScript Converter

Paste JSON and get TypeScript interfaces for every nested object, ready to drop into your project.

Generate TypeScript interfaces from JSON

Typing API responses by hand is slow and easy to get wrong. This converter reads a JSON sample and produces one exported interface per object shape: nested objects become their own named interfaces, arrays become typed arrays such as string[], and numbers, strings and booleans map to number, string and boolean. The output contains only type declarations, with no runtime code, so it adds nothing to your bundle.

How to use

  1. Paste a real response from the API you are integrating, for example from your browser's network tab.
  2. Set the type name to what the root object represents, such as User or ApiResponse.
  3. Copy the interfaces into a types.ts file and annotate your fetch result, for example const user: User = await res.json().

Frequently asked questions

Does it generate interfaces or type aliases?
It generates exported interfaces. For typing API data they behave the same as object type aliases, and you can rename or convert them freely after copying.
How do I get optional properties (field?: string)?
The generator only knows what the sample shows. Put several objects in an array where some of them omit the field, and that property is generated as optional. A field that is always null in the sample is typed as null, so give it a real value if you know its type.
Do the interfaces validate data at runtime?
No. TypeScript types are erased at compile time, so a malformed response will not throw. If you need runtime checks, generate a JSON Schema with the JSON Schema tool and validate against it, or use a validation library.

Example: JSON to TypeScript

Input JSON

{
  "id": 42,
  "name": "Ada Lovelace",
  "email": "ada@example.com",
  "roles": ["admin", "editor"],
  "profile": { "bio": "Mathematician", "website": "https://example.com" }
}

Generated TypeScript (User)

export interface User {
    id:      number;
    name:    string;
    email:   string;
    roles:   string[];
    profile: Profile;
}

export interface Profile {
    bio:     string;
    website: string;
}

Convert JSON to other languages