Skip to content
Free developer tool

JSON to TypeScript

This tool reads a JSON sample, such as an API response, and writes TypeScript interfaces that describe it. Front-end and Node.js developers use it to type fetch results and config objects without writing every field by hand.

  • Runs in your browser
  • Free, no account needed
  • Copy or download the result
Private: runs on this device

Input

169 characters

A valid identifier, such as User

Result

export interface Root {
  id: number;
  name: string;
  email: null;
  tags: string[];
  address: Address;
  orders: Order[];
}

export interface Order {
  id: number;
  total: number;
  coupon?: string;
}

export interface Address {
  city: string;
  zip: string;
}

Example

Input
{"id":42,"name":"Ada","email":null,"tags":["admin","dev"],"address":{"city":"London","zip":"NW1"},"orders":[{"id":1,"total":19.99},{"id":2,"total":5,"coupon":"SPRING"}]}
Result
export interface Root {
  id: number;
  name: string;
  email: null;
  tags: string[];
  address: Address;
  orders: Order[];
}

export interface Order {
  id: number;
  total: number;
  coupon?: string;
}

export interface Address {
  city: string;
  zip: string;
}

How to use the json to typescript

  1. Paste a JSON sample into the JSON sample box.
  2. Set the Root type name, such as User.
  3. Pick a Declaration style: interface or type alias.
  4. Press Run, then Copy result or Download.

How it works

Each nested object gets its own exported declaration, named from its key in PascalCase. Array items get a singular name, so orders becomes Order.

All objects in an array are merged into one shape. A field missing from some of them is marked optional with ?, and a field with different kinds of values becomes a union such as string | number.

null values add | null, empty arrays become unknown[], and empty objects become Record<string, unknown>.

Keys that are not valid identifiers, such as my-key, are written in quotes. Objects with exactly the same fields share one declaration.

The types describe only your sample, so check optional fields and unions against your real data.

Everything runs in your browser. Your input is not uploaded or stored.

Questions and answers

Should I use interface or type?

Both work for object shapes. Interfaces can be extended and merged later, while type aliases are often preferred for unions. Pick the style your project already uses.

Why is a field marked optional?

At least one object in an array did not have that field, so the generated type allows it to be missing.

Does it detect dates or enums?

No. JSON has no date type, so dates are typed as string, and repeated text values are not turned into enums.

Is my JSON uploaded?

No. It runs in your browser, and nothing you paste is sent to a server.

All 220 SnowRock tools