API Response Types
Runs in your browserPaste a real API response and get types you can trust. Every element of an array is read, not just the first, so a key that is missing once comes back optional rather than required.
Your JSON is processed locally in your browser and is not sent to our servers.
What was inferred
Generated types
How this one works
Every element of an array is read and merged, which is the whole point. Given [{"id":1,"nickname":"asha"}, {"id":2}], a converter that stops at the first element calls nickname a required string. It isn’t. It’s optional, and you find that out in production. Here a key missing anywhere becomes optional, a value that is sometimes null becomes nullable, and a field that is a string in one place and a number in another becomes a union rather than a guess.
Optional and nullable are kept apart, because they are different things: a field that can be absent is not the same as one that can be null, and only one of them needs a default. Each language then says it the way it can: ? in TypeScript, a pointer in Go, Option in Rust, | None in Python.
Two objects with identical fields become one named type, so a response carrying billing_address and shipping_address gives you one Address rather than two you have to merge. ISO timestamps are read as dates where the language has a date type, and snake_case keys are renamed to the casing the language expects, with the wire name kept in an annotation.
Questions
Why do I get better types if I paste more than one response?
Because optionality can only be observed. One object tells you which keys exist in that object; several tell you which keys are missing sometimes. Paste an array of real responses, or a list endpoint’s output, and the fields that vary come back optional instead of required.
What is the difference between optional and nullable here?
Optional means the key was absent from at least one sample. Nullable means the key was present with a null value. They need different code: an absent key needs a default or a question mark, a null value needs the type widened. Tools that collapse the two give you code that compiles and then fails on real data.
Is my JSON sent anywhere?
No. The inference and all nine generators are JavaScript running in this page, so a pasted response never leaves the tab. There is no server to receive it. Check your browser’s network panel while you type, or go offline and keep using it.
Why is a field typed as unknown or Any?
Because the sample gave nothing to go on: the value was null in every object, or the array was empty everywhere it appeared. Guessing a type there would be inventing one. Paste a sample where the field has a value and it will be inferred.
Should I use the Zod schema or the TypeScript interface?
The interface if the data is already yours; the schema if it is arriving over the network. An interface is a compile-time promise, and await response.json() is any, so the interface you assert into is a wish. A schema checks the same shape at the boundary, and you get the interface from it for free with z.infer.