JSON → TypeScript Interface
Generate TypeScript interfaces from any JSON sample — types are inferred recursively and named after each key.
export interface Post {
id: number;
title: string;
tags: string[];
}
export interface Address {
city: string;
zip: string;
}
export interface Root {
id: number;
name: string;
active: boolean;
joinedAt: string;
roles: string[];
address: Address;
posts: Post[];
}How to use
- Paste a JSON sample.
- Set a root type name and choose interface or type-alias style.
- Pick array handling — merge (safer) or first (faster).
- Copy the generated TypeScript.
About this tool
ShowHide
Paste any JSON and get TypeScript interfaces or type aliases, with a separate declaration for each nested object. Unlike converters that read only the first element of an array, this one merges the shape of every element, which is what makes the result trustworthy on real API responses: a key present in some records and missing from others comes out as possibly undefined, and a field that is a string in one record and a number in another comes out as a union of both rather than silently taking whichever appeared first. Arrays of mixed primitives are unioned the same way. Choose whether to emit interfaces, type aliases, or plain declarations without the export keyword. Everything runs locally in your browser — your JSON is never uploaded.
Frequently asked questions
Why does my array of users produce a User interface?
Keys that look plural (users, posts, tags) are singularized for the nested type name. So 'posts': [...] generates a Post interface, used as Post[].
What does merge vs first do?
Merge walks every array item and unions the field types, so 'optional' fields that are missing in some items become 'field?'. First only looks at item zero — fast but misses union types and optionality.
Are dates inferred as Date?
No — TypeScript can't tell a date string from any other string at compile time. The tool keeps them as 'string' so the output is correct in strict mode.
What about null?
null becomes its own type. If a field is sometimes null in merge mode, you get 'field: string | null' instead of 'field: string'.
Should I always use merge rather than first?
For real API responses, yes. First reads only the opening element, so a field missing from it or typed differently later is simply not represented, and you find out at runtime. Merge walks every element and unions what it finds, which is slower on huge inputs and correct on ragged ones.
Why isn't an ISO timestamp typed as Date?
Because in JSON it is a string, and TypeScript describes the shape of the parsed data rather than what you intend to do with it. JSON.parse never produces a Date, so typing the field as Date would be a lie until something converts it. Convert first, then narrow the type.
Related tools
JSON to Zod Schema Generator
Turn a JSON object into a Zod validation schema with inferred types, in your browser.
Developer
JSON Schema Generator
Paste any JSON and get a draft-07 JSON Schema that matches its shape — types inferred, formats detected, required fields filled in.
Developer
JSON to GraphQL Schema (SDL) Converter
Turn a JSON object into GraphQL type definitions (SDL) with scalar mapping, in your browser.
Developer
JSON to JSDoc @typedef Generator
Turn a JSON object into JSDoc @typedef blocks with @property tags, in your browser.
Developer
Mock Data Generator
Generate realistic fake records for testing — names, emails, dates, IDs, lorem — exported as JSON, CSV, or SQL INSERTs.
Developer
JSON to Python Dataclass Converter
Turn a JSON object into Python @dataclass definitions with type hints, in your browser.
Developer