JSON to TypeScript Interface
CodeConvert any JSON object to a TypeScript interface instantly. Generates nested interfaces, array types, and union types from your JSON structure. In-browser, no data uploaded.
What is a JSONโTS?
The JSON to TypeScript Interface Formatter converts a JSON object into a TypeScript interface definition โ automatically inferring the type of each key from its value. It handles nested objects (generating separate named interfaces), arrays (inferring element types), and mixed-type arrays (generating union types).
TypeScript is the dominant typed superset of JavaScript for web and backend development. When working with REST APIs, GraphQL responses, database records, or configuration files, developers frequently need to write TypeScript interface definitions that match the JSON structure. Writing these by hand for deeply nested JSON objects is slow and error-prone.
This formatter uses a real JSON sample (an actual API response, a database document, or a config file) as input and generates the full TypeScript interface tree in one step.
What it generates:
- Primitive types:
string,number,boolean,null - Nested object types: separate
interfacedefinitions named from the key in PascalCase - Array types:
string[],number[],NestedType[], or union arrays(string | number)[] - Optional
exportkeyword on all interfaces
What it does not generate: optional fields (?), union types for nullable properties, Date from ISO strings, enums, or runtime validators. The output is a starting point โ review and refine for production use.
Related tools: JSON Formatter to inspect and beautify the raw JSON, JSON to CSV Formatter to convert JSON to CSV for spreadsheet use.
All processing is client-side. No data is transmitted.
How to use this JSONโTS calculator
- Paste the JSON โ paste a real API response, database document, or config file into the input textarea.
- Set the root interface name โ change from the default
RootObjectto match your naming convention. - Toggle export โ choose whether to add
export interfaceor plaininterface. - Copy the output โ the generated TypeScript interfaces appear instantly; click the copy button.
- Refine the types โ mark optional fields, add
| nullto nullable properties, fixunknown[]arrays. - Related tools: use the JSON Formatter to inspect and beautify raw JSON first.
Formula & Methodology
Type inference rules: | JSON value | TypeScript type | |---|---| |"hello"|string| |42,3.14|number| |true,false|boolean| |null|null| |[]|unknown[]| |["a", "b"]|string[]| |[1, "x"]|(number \| string)[]| |{ "key": value }| Named interface (key โ PascalCase) | Nested interface naming: key name is converted to PascalCase using word boundary detection (camelCase split, snake_case split, kebab-case split). Before and after example:json { "name": "Alice", "age": 30, "address": { "city": "New York", "zip": "10001" } }typescript export interface Address { city: string; zip: string; } export interface RootObject { name: string; age: number; address: Address; }
Frequently Asked Questions