Why use JSON to TypeScript?
- Recursive conversion: nested objects become separate named interfaces automatically
- Arrays of objects use the first element to infer the item type with correct [] notation
- Optional-property mode marks null fields with ? to reflect real-world API variability
- 100% in-browser — no data is ever uploaded, safe to use with sensitive payloads
About JSON to TypeScript
Manually writing TypeScript interfaces for every API response is tedious and error-prone. The JSON to TypeScript converter automates the process: paste any JSON object or array and it walks the structure recursively, extracting nested objects into their own named interfaces and correctly typing arrays, primitives and null fields. You can customise the root interface name and choose whether null values produce optional (?) properties.
Because the conversion runs entirely in your browser, your data never leaves your device — safe to use with real API responses containing user data or credentials. The output is clean, copy-ready TypeScript that integrates into any project without additional dependencies or post-processing.
How to use JSON to TypeScript
- 1
Paste your JSON
Copy a JSON response from your API client, browser DevTools or any source, then paste it into the input panel on the left.
- 2
Configure options
Set the root interface name (defaults to "Root") and choose whether null fields should be marked as optional properties.
- 3
Copy the TypeScript
Click "Generate Types" and the interfaces appear instantly on the right. Click "Copy TypeScript" to paste them straight into your project.
Frequently asked questions
How are nested objects handled?
Each nested object is extracted into its own named interface. The name is derived from the parent interface name plus the field name with a capitalised first letter — so a "address" field inside "Root" becomes "RootAddress".
What happens with arrays of mixed types?
If an array contains elements of different types, the tool emits a union type such as (string | number)[]. If the array contains objects, the first element is used as the representative shape.
What does the optional (?) setting do?
When "Mark as optional" is selected, any field whose sample value is null gets a ? appended to its key (e.g. metadata?: null). This is useful because real APIs often return null for fields that may be absent.
Can I use the output directly in a TypeScript project?
Yes. The generated interfaces use standard TypeScript syntax with no imports or decorators, so you can paste them into any .ts or .d.ts file. You may want to add export before interface for module use.
Is there a size limit on the JSON input?
There is no enforced limit, but very large JSON payloads may take a moment to process since everything runs in the browser. For most real-world API responses the conversion is instantaneous.
Does the tool support JSON arrays at the root level?
Yes. If the root value is an array of objects, the tool infers the interface from the first item. If it is an array of primitives, it emits a simple type alias like "type Root = string[]".
Related developer tools
Browse more free tools
Explore every category in our toolbox.