Skip to content
Toolcroft

JSON to TypeScript Interface Generator

Developer Tools

Convert JSON objects to TypeScript interfaces automatically. Handles nested objects, arrays, null, and mixed types.

interface Root {
  id: number;
  name: string;
  email: string;
  active: boolean;
  score: number;
  tags: string[];
  address: Address;
}

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

How to use this tool

  1. Paste your JSON into the input area.
  2. Optionally change the root interface name.
  3. Copy the generated TypeScript interfaces.

How JSON-to-TypeScript inference works

The tool analyzes your JSON structure and infers TypeScript interface or type definitions. Each JSON object becomes an interface; arrays become typed array types (T[]). Primitive JSON values map to TypeScript primitives:

JSON typeTypeScript type
stringstring
numbernumber
booleanboolean
nullnull or T | null
objectinline interface
arrayT[]

Readonly and optional properties

The generated interfaces use plain properties by default. After generation, consider:

  • Adding readonly to properties that should never be mutated after creation
  • Adding ? (e.g. name?: string) to fields that may be absent in some API responses
  • Using Readonly<T> or ReadonlyArray<T> utility types for deep immutability

Discriminated unions

When an API returns objects with different shapes based on a type or kind discriminant field, TypeScript's discriminated union pattern provides precise type narrowing. The auto-generated interface won't produce this pattern automatically; you'll need to refine the generated types manually after generation.

Runtime validation with Zod

TypeScript types are erased at runtime - they provide no protection against unexpected API responses. To validate actual API responses at runtime, pair your generated types with a runtime schema library:

  • Zod: the most popular TypeScript-first validation library; infers types from schemas so you maintain one source of truth
  • Valibot: similar API to Zod with a smaller bundle size
  • AJV: JSON Schema-based validation; integrates with existing JSON Schemas

Frequently asked questions

Does it support nested objects?

Yes. Nested objects generate nested interfaces with descriptive names derived from their property keys.

Browse all developer tools