JSON to TypeScript conversion lets you instantly generate strongly-typed interfaces from any JSON data. Instead of manually writing TypeScript types for API responses, config files, or data schemas, paste the JSON and get accurate, ready-to-use TypeScript interfaces with proper nesting, optional fields, and union types for mixed arrays.
JSON Input
Options
TypeScript Output
// Paste JSON on the left to generate TypeScript interfaces
How to Use the JSON to TypeScript Converter
When working with REST APIs, you often receive JSON responses that need to be typed in TypeScript. Manually writing interfaces for deeply nested JSON is tedious and error-prone. This converter analyzes your JSON structure and generates accurate TypeScript interfaces in seconds, handling nested objects, arrays, nullable fields, and mixed-type arrays automatically.
Step 1: Paste Your JSON
Copy your JSON data — from a REST API response, a config file, or any JSON source — and paste it into the JSON Input field. The tool validates your JSON in real time and shows a parse error if the input isn't valid JSON. Click Load sample to see a demonstration with a realistic API response structure.
Step 2: Configure Options
Set the Root interface name to match your use case (e.g., "ApiResponse", "UserProfile", "Config"). Use the checkboxes to customize the output: Export interfaces adds the export keyword. Use type alias generates type declarations instead of interface. Make all optional adds ? to every field — useful when deserializing partial data. Add readonly marks all fields as read-only.
Step 3: Copy and Use the Interfaces
Click Copy to copy all generated interfaces to your clipboard. Paste them into your TypeScript file, adjust names as needed, and use the types in your code. For complex API responses with many levels of nesting, sub-interfaces are generated with names derived from the key names — for example, a userSettings key generates a UserSettings interface.
Type Inference Rules
Primitives: JSON string → string, number → number, boolean → boolean, null → null. Arrays: Uniform arrays → type[]; mixed arrays → (type1 | type2)[]. Nested objects: Each nested object generates a named sub-interface. Null values: When a field is null in your sample, it's typed as T | null for safety.
FAQ
Is this JSON to TypeScript converter free?
Yes, this JSON to TypeScript converter is completely free with no usage limits. Convert any JSON to TypeScript interfaces with no account or payment required. Everything runs in your browser — your data never leaves your computer.
How does the type inference work?
The tool analyzes each JSON value and maps it to the most accurate TypeScript type: strings become string, numbers become number, booleans become boolean, null becomes null, arrays become typed arrays (e.g., string[]), and objects become named interfaces. For arrays with mixed types, a union type is generated (e.g., string | number | null).
How does it handle nested objects?
Each nested object generates a separate named interface. The interface name is derived from the key name, PascalCased (e.g., a key 'userProfile' generates an interface named UserProfile). The root object becomes the Root interface (or whatever name you specify). Sub-interfaces are listed after the main interface in the output.
How are optional fields detected?
Optional fields are detected when analyzing arrays of objects — if a key appears in some objects but not others, it's marked as optional (with the ? modifier). You can also force all fields to be optional using the 'Make all optional' toggle.
Can I use 'type' instead of 'interface'?
Yes. Toggle the 'Use type alias' option to generate type MyType = {} declarations instead of interface MyType {} declarations. For most use cases, interfaces and type aliases are interchangeable, but interfaces support declaration merging and are generally preferred for object shapes.
Does it handle arrays of objects?
Yes. Arrays of objects generate a typed interface for the object shape, and the array field type becomes InterfaceName[]. If an array contains multiple different object shapes, the tool will generate a best-effort interface based on the merged keys from all items.
What happens with empty objects or empty arrays?
Empty objects ({}) are typed as Record<string, unknown> since no properties can be inferred. Empty arrays ([]) are typed as unknown[] since the element type can't be determined. These are safe TypeScript types that you can refine manually after generation.