Online JSON to TypeScript Interface Generator

Convert raw JSON data into clean, strongly typed TypeScript interfaces or type aliases with nested type extraction.

Runs locally 0 lines • 0 bytes Ready
Tip: drop a file anywhere on the page
Input
Paste, type or drop a file
Result
Updates as you type
// Output will appear here…
About this tool

How the JSON to TypeScript works

Generate type-safe TypeScript interfaces and types from JSON payloads. Nested interfaces, union detection, and optional fields handled automatically.

How to use the JSON to TypeScript

  1. Paste a sample JSON response.
  2. Choose interfaces or type aliases and set the root name.
  3. Copy the generated types into your project.

JSON to TypeScript example

Input
{"id":1,"name":"Ali","tags":["x"],"address":{"city":"Pune"}}
Result
export interface Root {
  id: number;
  name: string;
  tags: string[];
  address: Address;
}

export interface Address {
  city: string;
}

When to use it

  • Typing API responses in React, Angular or Node.js projects.
  • Creating models for fetch and axios calls.
  • Documenting data shapes for teammates.

Tip: Use a sample with every optional field filled in; fields missing from the sample cannot be inferred.

Nested Interface Extraction

Automatically creates clean, distinct PascalCase interfaces for nested objects (e.g. Address, Item).

Optional & Union Field Detection

Scans arrays of heterogeneous objects to identify optional properties (field?: type) and union types.

Interface or Type Alias Toggle

Generate export interface or export type declarations based on your codebase conventions.

Download .d.ts or .ts

Copy declarations directly into your frontend or backend project, or download as a definition file.

FAQ

Common questions

How does this tool detect optional fields?

When you provide an array of objects, the generator inspects all objects. If a property appears in some items but not all, it is marked with ? (optional).

Does it handle mixed array types?

Yes! Arrays with mixed elements (e.g. strings and numbers) generate union types such as (string | number)[].

Can I choose between interface and type?

Yes! Use the toggle in the toolbar to switch between "interface" and "type" output.

Can I change the root interface name?

Yes, customize the root interface name (e.g. UserResponse, ApiResponse) in the options input.