JSON → TypeScript Interface
Generate a TypeScript interface or type from any JSON payload, with optional and readonly toggles.
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.
