Skip to content

JSON a TypeScript

Convierte un JSON de ejemplo en interfaces o alias de tipo de TypeScript, infiriendo objetos anidados, arrays y campos opcionales.

Sin subidas
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;
}

Cómo usar JSON a TypeScript

  1. 1Abre JSON a TypeScript. Funciona en tu navegador, sin registro.
  2. 2Escribe o pega tus datos.
  3. 3Copia o descarga el resultado.

Preguntas

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.

Más herramientas