JSON to TypeScript Converter
Paste a JSON sample, get TypeScript interfaces — nested types, arrays, optionals and unions inferred automatically.
From API response to typed code
You call an API, stare at the JSON, and start typing interface … by hand — the least fun minutes of TypeScript development. This tool infers the interfaces from a sample: every nested object becomes its own named interface, arrays become Element[] types, and values that are sometimes null become union types like string | null. The inference engine is purpose-built for this site and runs entirely in your browser — your sample never leaves the page.
Sample-based inference: what to feed it
The generator can only know what your sample shows. Two practical tips: use a sample where arrays contain several entries (so optional fields are seen both present and absent), and prefer a real response over a hand-made minimal one — the point is to capture reality, including its irregularities. Fields missing in some array entries come out as optional? properties, mixed number/string values as unions.
Interfaces only, no runtime baggage
The output is deliberately just types — no decoding helpers, no class wrappers — because in TypeScript, types are usually all you want: paste them into your project and annotate your fetch results. If you also need runtime validation, generate a request to test with and consider a schema validator on top; types and runtime checks are different jobs.
Frequently asked questions
Why is a field typed as string | null or marked optional?
Because the sample showed it that way: a null value produces a null union, and a field present in some array entries but not others becomes optional (name?). That is inference working correctly — widen or narrow by editing the sample or the generated type.
Can it generate type aliases or Zod schemas instead of interfaces?
This page generates plain interfaces — the form virtually all TypeScript codebases accept. Runtime-schema flavors (Zod, io-ts) encode validation policy that you should own in code; the generated interfaces are a solid starting point to derive them from.
How are date strings typed?
As string — correctly so, because JSON has no date type and JSON.parse will give you a string at runtime. Convert at the boundary (new Date(user.lastLogin)) rather than lying to the compiler with a Date type.
Is my API response uploaded anywhere?
No — the inference runs completely in your browser (the generator library is loaded into the page, your data never leaves it). Paste production payloads without worry.