Skip to content

JSON to TypeScript

Turn sample JSON into TypeScript interfaces or type aliases, with nested objects, arrays and optional fields inferred.

No uploads
export interface Root {
  id: number;
  name: string;
  email: string;
  active: boolean;
  tags: string[];
  address: Address;
  orders: Order[];
}

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

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

How to use JSON to TypeScript

  1. 1Open JSON to TypeScript. It runs in your browser, no sign-up.
  2. 2Type or paste your input.
  3. 3Copy or download the result.

Questions

How are optional fields detected?

When an array contains objects and a key is missing from some of them, that key is marked optional with ?.

What about null values?

null is kept in a union, e.g. string | null, so you can see which fields can be empty.

Is my JSON uploaded?

No — conversion happens entirely in your browser.

More tools