JSON to TypeScript Converter
Generate TypeScript interfaces or type aliases from a JSON sample: nested types, merged array items, optional fields, export keyword. Runs in your browser.
Your inputs and files stay in your browser
JSON Input
Paste a JSON sample — TypeScript interfaces are generated as you type.
In the editor, Tab indents. Press Esc, then Tab to move focus out.
TypeScript interfaces will appear here...
On this page
Paste a JSON sample — an API response, a config file, a test fixture — and get TypeScript declarations for it as you type. Nested objects become their own named interfaces, so the output can go straight into a .ts file.
Detailed Functionality
Types are inferred from the values: string, number, boolean, null, arrays as T[], mixed arrays as unions such as (number | string | null)[], and an empty array as unknown[]. Every nested object gets an interface named after its path in PascalCase (shipping_address inside Order → OrderShippingAddress). All objects of an array are merged into one item type: a key missing in some elements becomes optional, and a key with different value types gets a union.
Options: Root name sets the top-level type name (default Root); export keyword adds export to every declaration; Optional fields (?) — on by default — marks keys whose value is null as optional; Use type alias writes type X = { … }; instead of interface X { … }. A root array produces an alias such as export type Users = UsersItem[];. Keys that are not valid identifiers are quoted ("order-id": string;), and colliding type names get a number suffix.
The output is rebuilt on every edit (after a short pause) and on Convert or Ctrl+Enter; invalid JSON shows the parser error. The result sits in a read-only editor you can Copy or save with Download .ts as types.ts. Everything runs locally — the sample is never uploaded or saved.
Practical Examples
API object: {"id":7,"user_name":"ann","tags":["a"],"manager":null} with Root name User and export keyword gives export interface User { id: number; user_name: string; tags: string[]; manager?: null; }.
Array of different objects: [{"id":1,"email":"[email protected]"},{"id":2,"phone":"555"}] with Root name Users gives export interface UsersItem { id: number; email?: string; phone?: string; } and export type Users = UsersItem[];.
Type aliases and quoted keys: {"order-id":"A1","items":[{"sku":"x","qty":2}],"shipping_address":{"city":"Omsk"}} with Root name Order and Use type alias gives type OrderItemsItem = { sku: string; qty: number; };, type OrderShippingAddress = { city: string; }; and type Order = { "order-id": string; items: OrderItemsItem[]; shipping_address: OrderShippingAddress; };.
How to Use This Tool
Paste your JSON
Put a JSON sample into the JSON Input editor. The TypeScript Output updates automatically.
Adjust the options
Set the Root name and toggle export keyword, Optional fields (?) and Use type alias as needed.
Take the types
Click Copy to copy the declarations or Download .ts to save them as
types.ts.
Tips and Best Practices
- A sample only shows the values it contains: a field that is
nullin the sample is typed asnull, so replace it with the real type (for examplestring | null) by hand. - Include several array elements with different optional fields to get the item type right.
- All numbers become
number, and dates in ISO format staystring. - Turn off Optional fields (?) if
nullvalues are always sent explicitly and you wantmanager: nullas a required key. - Property names keep their original spelling; only type names are converted to PascalCase.