JSON to TypeScript Converter

Paste your JSON and get TypeScript interfaces instantly

JSON Input

TypeScript Output

export interface Coordinates {
  lat: number;
  lng: number;
}

export interface Address {
  street: string;
  city: string;
  state: string;
  zip: string;
  coordinates: Coordinates;
}

export interface Friends {
  id: number;
  name: string;
  closeFriend: boolean;
}

export interface Friends2 {
  id: number;
  name: string;
  closeFriend: boolean;
}

export interface Root {
  id: number;
  name: string;
  email: string;
  isActive: boolean;
  age: number;
  address: Address;
  tags: string[];
  scores: number[];
  friends: (Friends | Friends2)[];
  metadata: null | unknown;
  emptyList: unknown[];
}

JSON to TypeScript Converter

Generate TypeScript interfaces and type definitions from JSON data instantly. Paste your JSON payload and get clean, well-structured TypeScript types ready to use in your project. This tool handles nested objects, arrays, optional fields, and union types so you can skip the tedious manual typing.

Features

  • Convert any valid JSON into TypeScript interfaces or type aliases
  • Automatic detection of nested objects and generation of separate named interfaces
  • Array type inference including typed tuples and union arrays
  • Option to generate interface or type declarations
  • Configurable root type name and optional export keywords
  • Handles nullable fields and marks them with optional (?) syntax
  • Supports deeply nested structures without depth limits
  • Copy generated TypeScript to clipboard in one click

How to Use

  1. Paste your JSON data into the input editor on the left side.
  2. Set the root type name (defaults to "Root") and choose between interface and type output.
  3. Toggle options such as adding export keywords or making all properties optional.
  4. View the generated TypeScript definitions in the output panel instantly.
  5. Copy the result and paste it directly into your .ts or .d.ts file.

Use Cases

  • API Response Typing: Paste a sample API response to generate request and response types for your frontend services.
  • Configuration Files: Convert JSON config files into typed interfaces so your application catches misconfigurations at compile time.
  • Database Schemas: Turn a sample document from MongoDB or a JSON column in PostgreSQL into TypeScript types for your ORM layer.
  • Mock Data: Generate types from test fixtures to ensure your mock data stays in sync with your production interfaces.
  • Code Migration: Speed up JavaScript-to-TypeScript migrations by generating types from runtime JSON samples instead of writing them from scratch.

FAQ

Does it handle arrays with mixed types?

Yes. When an array contains elements of different types, the converter generates a union type. For example, an array like [1, "hello", true] produces the type (number | string | boolean)[], accurately representing the mixed content.

How are nested objects handled?

Each nested object is extracted into its own named interface. For instance, a user object containing an address object will produce both a User interface and an Address interface, keeping your type definitions clean and reusable.

Can I use the output in a .d.ts declaration file?

Absolutely. The generated interfaces are valid TypeScript and work in both regular .ts files and ambient declaration files. Enable the export option if you plan to import the types from another module.