Your data is never sent to a server or stored anywhere. All processing happens in your browser.

JSON to TypeScript Interface

TypeScript interface
 

How to Use


Paste JSON on the left and the corresponding TypeScript `interface` definitions appear on the right. Nested objects each become their own interface, and array element types are inferred. The root interface name is configurable.

Type Inference Rules


Type inference uses these rules: `null` → `null`, string → `string`, number → `number`, boolean → `boolean`, array → `T[]` (or `(A | B)[]` for mixed types), object → its own interface. Array-of-objects shapes are inferred from the first element. For full type fidelity, TypeScript's own structural type system is more accurate; this tool is a starting scaffold, not a replacement.

Use Cases


  • Drafting TypeScript types from a sample REST API response
  • Generating types via JSON from config files or YAML
  • Typing API responses when GraphQL isn't available
  • Migrating JS to TS — scaffolding data type definitions from real samples
  • Inferring types from sampled documents in schemaless databases (e.g., MongoDB)

Privacy


JSON parsing and type inference happen entirely in the browser. The input never leaves your device, so sensitive sample data stays local.

FAQ


Why does it generate interfaces instead of type aliases?

Interfaces are the idiomatic choice for describing object shapes in TypeScript and support declaration merging and extension. Each nested object becomes its own named interface so the output reads as a clean, reusable hierarchy rather than one deeply inlined type.

Can I paste production data or API responses with real values?

Yes. Parsing and type inference run entirely in your browser with no upload or storage, so even a response containing tokens or personal data stays on your device. Only the structure matters anyway — the generated types describe shape, not values.

How are types inferred from an array of objects?

The element type is inferred from the first element of the array. If later elements have extra or missing fields, those differences are not merged, so review the output when your samples are not uniform.

How are null, mixed arrays, and empty objects handled?

null infers to the `null` type, and a mixed array like [1, "a"] becomes a union element type such as (number | string)[]. Inference is best-effort scaffolding, so optional fields and exact narrowings should be hand-tuned afterward.

Can I rename the top-level interface?

Yes. The root interface name is configurable via the Root name field, which is handy when you want the generated type to match an existing domain name like User or ApiResponse.