JSON to TypeScript interfaces
Paste a JSON response and get TypeScript interfaces, with nested types extracted and optional fields detected. Nothing is uploaded.
About this converter
You have an API response and you need types for it. Writing them by hand is tedious, error-prone on anything deeply nested, and goes stale the moment the API changes. Pasting the response here gets you a starting point in a second.
Nested objects are extracted into their own named interfaces rather than being inlined, because inline anonymous types become unreadable past two levels and cannot be referenced anywhere else. Names are derived from the key that contained them, singularised where the key was plural - a users array yields a User interface, not a Users one.
Arrays of objects are merged across every element, not sampled from the first. This matters more than it sounds: if your response has fifty records and only three of them include a note field, inferring from the first record alone gives you a type that lies. The generator inspects all of them and marks fields missing from any record as optional, so the resulting type reflects what the data actually contains.
Number handling is intentional too. JSON has one number type, so an integer and a float look identical in the output - both become number, which is correct for TypeScript.
Be clear about what this can and cannot know. Types are inferred from the sample you paste, and a sample is not a schema. A field that is null in every record you have cannot be typed, and appears as null. A field that happens to be a string in your sample but can also be a number will be wrong until you see both. Treat the output as a first draft you review, not a contract - particularly for optionality, which is the thing a small sample gets wrong most often.
Everything runs in your browser, so pasting a real production response is safe.
Frequently asked questions
- Why is a field typed as unknown?
- The generator saw incompatible types for it across records, for example a string in one and an object in another. Narrow it by hand once you know which is correct.
- How is optionality decided?
- A field absent from at least one object in an array is marked optional. That is why pasting the full response matters more than pasting one record.
- Can it tell an integer from a float?
- Not meaningfully, and it does not need to - TypeScript has a single number type covering both.