JSON to TypeScript
Paste JSON and get TypeScript interfaces, including nested objects and arrays
Instructions
JSON to TypeScript Interface Instructions\n\n## Overview\nWhen you get the JSON returned by an API, writing the TypeScript types by hand takes a lot of time. This tool reads the JSON structure directly and recursively infers nested interfaces.\n\n## How to Use\n1. Paste the JSON into the input box; click "Fill Example" to see a complex example first\n2. Set the root interface name (default Root) and choose an `interface` or `type` alias\n3. If fields may be missing, check "Optional fields" to add `?` to every field\n4. Click "Generate TypeScript"; the result is output in reference order, with subtypes first and the root type last\n5. Click "Copy Result" to copy it\n\n## Notes\n- The types are inferred from this one JSON: a `null` field only yields `null`, and missing fields cannot be detected. For more accuracy, use multiple samples or add types by hand\n- When array elements have different structures, a union type is generated, for example `(A | B)[]`\n- An empty array can only be inferred as `unknown[]`; you need to fill in the type yourself\n- Field names that are not valid identifiers are wrapped in quotes, which is valid TypeScript syntax
❓ FAQ
What if the object types in an array are inconsistent?
The tool generates one interface for each distinct structure and writes the array element type as a union, for example `(User | Admin)[]`. You can narrow it down after generation based on your actual business logic.
Why is the type of a null field null?
Because there is only this one piece of data, it is impossible to tell whether it will be a string or a number later. It is recommended to add all the types that have appeared in real data, or manually change it to `string | null`.
Does it support generating Go or Java types?
Currently it only generates TypeScript. If you want to see the structure first, the nested interface names inferred by this tool are not hard to rewrite as structs in other languages.
🔗 Related Tools
📝 Related Articles
How to Use a Favicon Generator: Complete Steps from Image to Website Icon
Use a favicon generator to turn a square image into a website icon that displays correctly in browser tabs and on mobile home screens. From preparing assets to deployment troubleshooting, this covers it all in one go—just follow along to get it done.
tool-tutorialsHow to Use a Cron Expression Generator: Complete Beginner Steps
Use an online tool to select the five time fields, automatically generate a standard Cron expression with a human-readable time explanation, and learn to troubleshoot execution time deviations caused by time zones and field counts, so complex schedules no longer rely on guesswork.
tool-tutorialsHow to Use an Online CSV to JSON Tool: Beginners Can Get Started in Three Steps
Use a three-step process to complete an online CSV to JSON tool operation, covering option settings, result validation, error troubleshooting, large file handling, mobile operation, and API debugging scenarios. Beginners can follow along to get usable JSON data.
tool-tutorialsWhat Is HTML Formatting? A Beginner's Guide to the Key Points
Use a browser-based HTML formatting tool that runs locally to restore compressed or messy HTML into an indented, readable structure. Also understand the difference between formatting and minification, the troubleshooting order for messed-up indentation, and how to handle large files getting stuck and mobile no-install solutions.