About json to typescript
Typing API responses by hand is slow. Paste a JSON sample and the tool generates TypeScript interfaces for it.
What it infers
- Strings, numbers, booleans and nulls become the matching types.
- Arrays become typed lists, and nested objects become their own interfaces.
- Fields that are missing in some items can be marked optional if you give several samples.
Review the output
A single sample cannot show every possible value. Check types such as unions, dates (which arrive as strings) and optional fields before using the result.
A worked example
{"id":1,"name":"Asha","tags":["a"],"address":{"city":"Pune"}} becomes an interface with id: number, name: string, tags: string[] and an address of its own interface type with city: string. Name the root interface in the box to suit your code.
Improve the types
- Mark fields that are sometimes missing as optional with ?.
- Replace string with a union type when only a few values are allowed.
- Convert date strings to Date after parsing, since JSON has no date type.
