JSON to TypeScript
Generate TypeScript types from a JSON sample — merges array element shapes, infers unions & optional/nullable fields, dedupes identical shapes. Live, with interface or type output.
About this ToolHow it works, benefits & use casesTap to collapse
Turn a sample of JSON into ready-to-use TypeScript types, generated live as you paste. The tool walks the JSON, names a root type from the field you specify, and extracts nested objects into their own named interfaces rather than inlining everything. For arrays it can merge the shapes of all elements, producing a union of keys where properties that are missing from some elements become optional — so a real-world array of slightly different records still yields one accurate type. You decide whether to emit interfaces or type aliases, mark every property optional, add readonly modifiers, and prefer unknown over any for values it cannot infer. Each generation reports how many interfaces and properties were produced, how many are optional, and the maximum nesting depth. The output is a clean .ts file you can copy, download or share, and the whole thing runs in your browser with no upload.
How to Use
- 1Type a root type name (defaults to Root) and choose whether the output is an interface or a type alias.
- 2Toggle the modifiers you want: "All optional", "Readonly", "Prefer unknown" (instead of any), and "Merge array shapes".
- 3Paste a representative JSON sample into the input panel, or click "Load example".
- 4Watch the TypeScript regenerate live; press "Generate TypeScript" to validate the JSON.
- 5Review the generation summary (interfaces, properties, optional props, max depth) then copy, download types.ts, or share the result.
Key Benefits
- Extracts nested objects into separate named interfaces instead of inlining them
- Merges array element shapes into a single type with missing keys marked optional
- Choose interface output or type aliases to fit your code style
- Optional all-optional and readonly modifiers for defensive typing
- Prefer unknown over any for safer fallbacks
- Generation summary with interface, property, optional and depth counts
- Live output with copy, .ts download and shareable URLs — all in-browser
Common Use Cases
- Typing an untyped third-party API response from a captured sample
- Bootstrapping interfaces for a new feature directly from mock JSON
- Deriving a single type from a heterogeneous array of records
- Generating readonly types for immutable config objects
- Keeping frontend types in sync with a backend payload during development
Options
Mark every property optional (?)
Add readonly to every property
Use unknown instead of any
Union keys across array elements; missing → optional
0 characters · live
Paste JSON above to generate types live.
Was this tool helpful?
Share Your Experience
Help others discover this tool!
Related guide
Related tools
- JSON Path FinderFind and test JSON paths
- HTTP Header ParserParse and analyze HTTP headers
- User Agent ParserParse and analyze user agent strings
- Zod Schema GeneratorSmart JSON-to-Zod: merges array samples for optional/nullable/enum/format inference, emits the z.infer type, and validates any payload live
- API Response FormatterFormat and beautify API responses
- Type Guard GeneratorGenerate recursive runtime type guards (and assertion functions) from a TS interface, with a live validator that tests any JSON value
With "Merge array shapes" enabled (the default), it unions the keys across every element of an array. Properties present in some elements but not others are marked optional, so a single accurate interface describes the whole array instead of typing it from only the first element.
Yes. The Output selector switches between exported interface declarations and type aliases. Either way, nested objects are pulled out into their own named types and referenced from the parent.

