About this tool
Turn a sample API response or JSON configuration into an editable TypeScript type alias. This converter follows the actual values in your sample, including nested objects and heterogeneous arrays, and lets you name and download the result.
How to use
- Paste valid JSON or load the example.
- Choose a type name such as User or ApiResponse.
- Select Generate TypeScript, review the inferred shape, and copy the result or download types.ts.
How type inference works
JSON strings, numbers, and booleans become string, number, and boolean. A null value becomes null. Object keys are quoted to preserve spaces, punctuation, and reserved words. Arrays collect the distinct types observed in their elements into an Array union. Nested objects remain inline so there are no generated type-name collisions.
Arrays, empty collections, and missing fields
An array such as [1, "two", null] becomes Array<number | string | null>. An empty array becomes unknown[] because there are no elements to inspect. An empty object becomes Record<string, unknown>. Objects with different shapes in one array remain separate union members; the tool does not merge them into a single shape with optional properties.
Review your API contract
A sample cannot establish all values a service may return. A property present in this sample might be absent in a later response. Date strings remain strings, numbers are not inferred as enums, and nullable properties are not guessed. Compare the result with your API specification and add optional properties or domain-specific types where appropriate.
Types do not validate incoming data
TypeScript types describe values for static checking; this download is not a runtime validator or JSON Schema. Validate untrusted responses separately in your application. The converter processes the sample in the browser and does not save or upload it for generation. You may still want to remove real tokens and personal data before copying sample responses between applications.
Continue this workflow
Use the adjacent tool when the next step calls for a different input, output, or method.
Assumptions and limitations
- Maximum sample: 200,000 characters, 20,000 values, and 32 nesting levels; output is capped at 1,000,000 characters.
- Strict JSON only: no comments, trailing commas, undefined, functions, or JSON5.
- JSON numbers use JavaScript number parsing. Numeric precision and duplicate object keys cannot be recovered after parsing.
- Inference is based on one sample. Generated types must be reviewed and do not provide runtime validation.
Sources and standards
These authoritative references were used to verify the method and guidance on this page.
Frequently asked questions
Does this generate interfaces or type aliases?
It generates one exported type alias with inline nested objects. A type alias also supports a top-level array, primitive, or union.
Why is an empty array typed as unknown[]?
There is no element to infer from. Add representative items or replace unknown with the intended element type after generation.
Will it detect optional fields?
No. Fields present in an object are treated as required. Different object shapes become union members; review missing or optional fields against your API contract.
Can I paste confidential JSON?
Conversion happens locally and this tool does not save the sample. Use anonymized examples when possible and follow your organization’s data-handling rules.