Why it matters
Typing an API response by hand is slow and error-prone, and the first time a field turns out to be null in production the types were wrong. Generating them from real responses is faster and more accurate.
This converter looks at every item in every array, so a key that only appears sometimes becomes optional and a value that is sometimes a string and sometimes a number becomes a union. Identical shapes share one interface, and a Zod schema is written alongside so you can check the data at runtime too.
How it works
- InputA JSON response or file
- In your browserEvery item compared to find optional and null fields
- OutputTypeScript interfaces, type aliases or Zod schemas
Where it fits in a designer's workflow
- Plan
- Design
- Build
- Test
- Launch
By the numbers
Show the numbers as a table
| Output | Bytes |
|---|---|
| Sample JSON (indented) | 854 |
| TypeScript interfaces | 422 |
| Zod schemas | 832 |
How to use it
- Paste one or more sample responses as JSON.
- Name the root type and choose interfaces or type aliases.
- Check the optional keys and unions.
- Download or copy the TypeScript and the Zod schema.
FAQ
Why is a key marked optional?
Because at least one object in an array didn't have it. Paste more examples if that's wrong.
How are nulls typed?
As a union with null (string | null). If a key is always null, it becomes null; give a better sample to get the real type.
Why use Zod as well?
TypeScript types vanish at runtime. Zod checks that the data really matches, which matters for anything coming from an API.
Are dates detected?
No. ISO 8601 dates stay string, because JSON has no date type. Use z.string().datetime() in the Zod schema if you want them checked.