Skip to content

JSON to TypeScript

Paste a JSON sample and get ready-to-use TypeScript declarations that describe its shape.

Processed locally in your browser

Options
0 chars · 0 lines
The result will appear here.

What is JSON to TypeScript?

When you consume a JSON API in TypeScript you need types for the responses. Writing them by hand for large payloads is slow and error-prone, so a generator that infers them from a real sample saves time.

This tool walks your JSON, creates a named interface (or type alias) for each nested object, merges the objects found in an array so that keys missing from some items become optional (?), and builds unions when a field holds different types. You can choose the root name, interface or type style, the export keyword and readonly properties.

How does it work?

  1. Paste a representative JSON sample, ideally with several array items so optional fields can be detected.
  2. Set the root type name and choose interface or type, export and readonly options.
  3. Review the generated declarations in the output.
  4. Copy them into your project or download types.ts.

Common use cases

  • Typing the response of a REST endpoint before writing the client code.
  • Modelling a configuration file or a webhook payload.
  • Getting a first draft of types for a legacy API with no documentation.
  • Checking which fields of a response are sometimes missing or null.

Examples

Try this input in the tool above:

Input
{"id":1,"name":"Ada","email":null,"tags":["math","code"],"profile":{"age":36,"admin":false},"orders":[{"sku":"A1","qty":2,"note":"gift"},{"sku":"B2","qty":1}]}
Output
export interface Root {
  id: number;
  name: string;
  email: null;
  tags: string[];
  profile: Profile;
  orders: Order[];
}

export interface Profile {
  age: number;
  admin: boolean;
}

export interface Order {
  sku: string;
  qty: number;
  note?: string;
}

Privacy

JSON to TypeScript runs entirely in your browser. The text or files you provide are processed on your device and are not uploaded, logged or stored on our servers.

Limitations

Types are inferred from one sample only: a field that is always present in your sample may be optional in reality, and values like dates arrive as string. Review before committing.

Frequently asked questions

How are optional properties detected?

When several objects are merged (for example items of one array), a key that is absent from at least one of them is marked optional with a question mark. A key that is present but null keeps a null union instead.

How are nested objects named?

Each nested object gets an interface named after its key in PascalCase (orders becomes Order for array items). Objects with identical structure reuse the same declaration, and name collisions receive a numeric suffix.

Are big integers and dates handled?

All JSON numbers become number and dates become string, because JSON has no date type. Adjust those types by hand if your code parses them into Date or bigint.

More tools in JSON & Data →