Runs 100% in your browser — nothing is uploaded
JSON & Data Formats

JSON → TypeScript Interface

Generate a TypeScript interface or type from any JSON payload, with optional and readonly toggles.

JSON → TypeScript Interface
Client-side

About this tool

The JSON to TypeScript Interface tool infers a TypeScript type definition directly from a JSON payload — no schema, no annotations required. Paste a sample API response and instantly get a matching interface (or type alias) with the correct primitive types, nested object shapes, and array element types already inferred.

This is a pure, self-contained type-inference engine written specifically for this tool: it recursively walks the parsed JSON, inlining nested object shapes as anonymous nested types rather than generating a sprawl of separately named interfaces, which keeps the output readable and copy-pasteable directly into your codebase. Arrays are inspected for their element type — a homogeneous array of numbers becomes number[], while an array mixing strings and numbers becomes the union type (string | number)[]. Empty arrays fall back to unknown[] since no element is available to type from.

Options let you rename the root interface, switch between interface Foo {} and type Foo = {} syntax, mark every property as optional with a trailing ?, or prefix every property with readonly for immutable data models. Invalid JSON is caught and reported with a clear parse error before any generation is attempted, so you never get a half-broken interface.

Everything runs synchronously in your browser using plain JavaScript object walking — no external library, no network call. This makes it fast even on payloads with thousands of array elements, and safe to use with real (if non-sensitive) API response samples while prototyping a frontend data layer or a schema by hand.

FAQ

Does this generate separate named interfaces for nested objects?
No — nested object shapes are inlined directly inside the parent type rather than extracted into separate named interfaces. This keeps the output simple; you can always refactor a nested type out manually once you have the generated structure.
How are arrays with mixed types handled?
If every element is a primitive and the types differ, the tool emits a union type array, like (string | number)[]. If elements are objects, the type is inferred from the first element. Empty arrays produce unknown[].
What happens with invalid JSON?
The tool parses your input with JSON.parse before attempting any type generation. If parsing fails, you get a clear error message with no partial or guessed output.
Can I generate a type alias instead of an interface?
Yes — toggle "type X = {...}" to switch from interface Root { ... } syntax to type Root = { ... }. Both are functionally equivalent for object shapes in TypeScript.
Does this handle real-world API responses reliably?
For typical JSON API responses (nested objects, arrays of objects, primitives, null), yes. It works from a single representative JSON sample, so accuracy depends on how representative your sample is.