JSON to TypeScript Converter
Paste any JSON and instantly get clean TypeScript interfaces — types are inferred recursively, optional fields detected, and nested objects and arrays turned into named interfaces. Runs entirely in your browser.
About this tool
When you consume an API, the fastest way to get type safety is to describe its response as a TypeScript interface — but writing that by hand from a sample payload is dull and error-prone. This converter takes any JSON and generates clean interfaces automatically, inferring the type of every field and turning nested objects and arrays into their own named types.
It handles the details that matter for real payloads: recursive inference so deeply nested structures are fully typed, optional fields detected when a key is missing or null, and arrays typed by their element shape. You paste a response, you get interfaces you can drop straight into your codebase, all computed in the browser.
How to use
- Copy a representative JSON response or object from your API or fixture.
- Paste it into the input panel of the converter.
- The generated TypeScript interfaces appear instantly in the output panel.
- Review the inferred types, optional markers, and any extracted nested interfaces.
- Rename the root interface to match your domain if you like.
- Copy the interfaces and paste them into your .ts file.
Features
- Recursive type inference across deeply nested objects.
- Nested objects and arrays extracted into their own named interfaces.
- Optional fields detected and marked with a question mark.
- Arrays typed by element shape rather than a loose any.
- Clean, readable output ready to paste into a project.
- Handles arrays of objects by inferring a shared element type.
- Runs entirely in the browser — your JSON is never uploaded.
Frequently asked questions
Is the JSON I paste sent anywhere?
No. The conversion is performed locally in your browser with JavaScript. API responses often contain private data, so it never leaves your machine.
How does it decide a field is optional?
Types are inferred from the sample you provide. A field that is null, or that appears in only some elements of an array of objects, is treated as optional and marked accordingly. For fully reliable optionality, provide a sample that covers the variations.
What happens with nested objects?
Each distinct nested object becomes its own named interface, and the parent references it by name. This keeps the output readable instead of producing one giant inline type.
How are arrays typed?
An array is typed by the shape of its elements — an array of numbers becomes number[], and an array of objects becomes a named interface followed by []. Mixed-type arrays fall back to a union or a broader type.
Can it handle a top-level array?
Yes. If the root JSON is an array, the tool infers the element type and generates the interface for that element, which you can then use as an array type.