JSON to TypeScript — Interface Generator

Convert JSON objects to TypeScript interfaces instantly. Supports nested objects, arrays, optional and readonly properties. Free online tool.

Options

export interface Address {
  street: string;
  city: string;
  zipCode: string;
  country: string;
}

export interface Root {
  id: number;
  name: string;
  email: string;
  isActive: boolean;
  age: number;
  address: Address;
  tags: string[];
  scores: number[];
}

How the JSON to TypeScript Generator Works

  1. Paste a JSON object or array into the input field
  2. The generator recursively analyzes the data structure and types
  3. TypeScript interfaces are generated with proper naming and nesting
  4. Copy the interfaces directly into your TypeScript project

JSON to TypeScript Conversion Guide

For the best TypeScript interfaces, use a representative JSON sample that includes all possible fields. If certain fields are sometimes missing, the generator can detect optional properties. Nested objects create separate interfaces, keeping the code clean and reusable. Arrays of objects use the element type, and mixed-type arrays become union types. After generating, review the interfaces and adjust naming to match your project conventions.

When to Use a JSON to TypeScript Converter

Use this converter whenever you start integrating a new REST API or GraphQL endpoint in a TypeScript project. Instead of manually typing interface definitions from API documentation, paste a real response and generate accurate types instantly. It is also useful when refactoring JavaScript projects to TypeScript, creating type definitions for configuration files, or building mock data generators that need to match API shapes.

Common Use Cases

  • Generate TypeScript interfaces from REST API responses for type-safe front-end development JSON Formatter & Validator — Instant Results
  • Create type definitions for JSON configuration files in TypeScript projects
  • Speed up JavaScript-to-TypeScript migration by auto-generating interfaces from existing data JSON Tree Viewer — Expandable Visualizer
  • Build type-safe mock data generators that match production API shapes
  • Document GraphQL response types for shared frontend libraries

Expert Tips

  • Use a real API response rather than documentation examples — documentation may be outdated or incomplete
  • For APIs with optional fields, include multiple response samples to catch all possible properties
  • Review generated union types carefully — they may indicate inconsistent API responses that should be reported as bugs

Frequently Asked Questions

Does it handle nested objects?
Yes. Each nested object generates a separate named interface. The parent interface references the child interface by name, keeping the output organized and readable.
What about arrays with mixed types?
Arrays containing elements of different types generate a union type. For example, an array with both strings and numbers becomes (string | number)[].
Can I customize the interface names?
The root interface is named 'Root' by default. You can rename it after copying. Nested interfaces are named based on their property key with the first letter capitalized.
Does it support optional properties?
Yes. When configured, properties that may be null or undefined are marked with the ? modifier in the generated interface.
Is my JSON data secure?
Yes. All processing happens in your browser. Your JSON data is never transmitted to any server.

Related Tools