🧩

JSON to TypeScript

Paste JSON and get TypeScript interfaces, including nested objects and arrays

Note: The types are inferred from this JSON, not a JSON Schema. When array elements have inconsistent structures, a union type is generated, and field names that are not valid identifiers are quoted.

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.