JSON to TypeScript
Generate TypeScript interfaces from a JSON sample instantly. Paste an API response or object and get clean, typed interfaces — nested types, arrays, optional fields, and unions are all inferred. Runs entirely in your browser.
How to Use
- Paste a JSON object or array — an API response works well.
- Set the root interface name (defaults to “Root”).
- Click Generate to produce the TypeScript interfaces.
- Toggle the export keyword if you want exported interfaces.
- Copy the result into your .ts file.
From a sample to a type, automatically
One of the small frictions of working in TypeScript is hand-writing interfaces for data you already have a sample of — an API response, a config file, a webhook payload. This tool removes that step. It parses your JSON, walks the structure, and emits a clean set of interface definitions: every nested object becomes its own named interface referenced from its parent, arrays become typed arrays, and primitive values map to string, number, or boolean. Paste a representative example and you get a typed scaffold in an instant, ready to drop into your project and refine. It is the fastest way to go from “I have some JSON” to “my code knows the shape of this JSON.”
The clever bits — and the limits
Two details make the output noticeably better than a naive converter. First, optional-field detection: give it an array of objects and it compares every element, marking any key that is missing from some of them with a ? — exactly how a real API where some fields are absent should be typed. Second, key merging: an array of a hundred similar objects yields one interface, not a hundred, because their keys are unioned together. It is honest about its limits, though, and you should be too. JSON simply cannot carry all the information TypeScript wants: a field whose only sample value is null can only be typed null; a string that is really an ISO date or one of three allowed values is still just string; and the tool cannot tell an integer ID from a floating-point measurement. So treat the result as an excellent first draft — accurate in structure, worth a pass to narrow the types that only you, knowing the domain, can narrow.
About this tool
Paste JSON, name the root interface, generate, and copy. Toggle export if your types live in a module. Everything runs locally in your browser — nothing is uploaded. Need to move data between formats instead? Use the JSON ⇄ CSV Converter, or tidy raw JSON with the JSON Formatter.
About the JSON to TypeScript
Meet the JSON to TypeScript: a free, no-fuss tool for web development and data tasks with nothing to install and no sign-up. Generate TypeScript interfaces from a JSON sample instantly. Paste an API response or object and get clean, typed interfaces — nested types, arrays, optional fields, and unions are all inferred. Runs entirely in your browser.
How it works
Enter a number and choose your units — the converted value shows instantly. Everything runs locally, so nothing you type leaves your device. Double-check the direction of the conversion and you are set.
Want the deeper story? The Knowledge Base explains the ideas behind the tools in more detail.
Frequently Asked Questions
How are nested objects and arrays handled?
Each nested object becomes its own named interface, named after the key it appears under (in PascalCase), and referenced from the parent. Arrays become typed arrays — an array of objects produces a single interface and a Type[] reference, with the tool merging the keys of every element so the interface covers them all. Arrays of mixed primitives become a union like (string | number)[].
How does it decide which fields are optional?
When you give it an array of objects, the generator looks across every element. A key present in all of them is required; a key present in only some is marked optional with a question mark. That is why pasting a representative array, rather than a single object, produces the most accurate types — the more examples it sees, the better it distinguishes required from optional fields.
Is the inference perfect?
It is a strong starting point, not a substitute for thinking about your types. JSON cannot express everything TypeScript can: a null value alone infers null (it cannot know the non-null type), every string is just string even if it is really an enum or a date, and a number could be an int or float. Treat the output as a fast first draft you refine — replacing null-only fields, narrowing strings to literal unions, and renaming where the key-based names are not ideal.
Is my JSON uploaded?
No. Parsing and type inference run entirely in your browser with JavaScript. Nothing you paste is sent anywhere.
How do I use the JSON to TypeScript?
Simply type or paste your value and read the result, which refreshes the instant you change something. There is nothing to submit and nothing to wait for.
Do I need to install or sign up for anything?
Not at all — it runs in the browser with nothing to install and no account. After it loads once, it even works without an internet connection.
Is my information private?
Yes. Everything happens in your browser. Nothing you type is sent to a server or saved anywhere.
Common Use Cases
Type an API response
Paste a sample response and get interfaces to type your fetch calls and state.
Build DTOs fast
Turn example payloads into data-transfer-object interfaces in seconds.
Migrate JS to TypeScript
Generate types for the shapes flowing through legacy JavaScript code.
Document a data shape
Produce a readable, typed description of any JSON structure.
Last updated: