About JSON to TypeScript

Generates TypeScript interfaces from a JSON sample, entirely in your browser. Nested objects become their own named interfaces, arrays of objects are merged into a single interface where keys missing from some elements are marked optional, primitive and mixed arrays become typed or union arrays, and null values are typed as null. Give it one representative response from an API and paste the result straight into your code — no need to hand-write the types.

  • Nested objects are extracted into separate named interfaces and referenced by name
  • Arrays of objects are merged: keys present in every element are required, others become optional (key?)
  • Mixed arrays become union element types, e.g. (number | string)[]
  • null is typed as null; empty arrays become unknown[]
  • Name collisions between differently-shaped objects are disambiguated automatically
  • Runs fully client-side — your JSON never leaves the browser

Frequently Asked Questions

How are optional fields detected?
From arrays of objects. If a key appears in some array elements but not all, it is marked optional (key?). A single object has all of its keys treated as required, since the sample only shows them present.
What happens with arrays of different shapes?
Arrays of objects are merged into one interface combining all keys (optional where not universal). Arrays of mixed primitives become a union element type like (number | string)[]. Empty arrays become unknown[] since there is nothing to infer from.
Does it handle deeply nested JSON?
Yes — it recurses through any depth, creating a named interface per object shape and wiring them together, so the output is ready to paste into a .ts file.

More Development Tools

All Development tools