How the types are inferred
Every object becomes its own named interface, named after the key that holds it in PascalCase (shipping → Shipping, line_items → LineItem for the elements of an array). Strings, numbers and booleans map to string, number and boolean; null maps to null; an empty array becomes unknown[] because there is nothing to infer from.
When an array contains several objects, they are merged into one interface: a key that appears in only some of the items becomes optional (key?: type), and a key whose value differs between items becomes a union such as string | number. Pasting a response with several items therefore gives more accurate types than a single example.
Options
Choose interface or type aliases, name the root type, add export and readonly modifiers, and optionally turn fields that are null in the sample into optional fields — useful when null in your sample really means "sometimes missing". Inferred types describe the sample, not the API contract: review fields that were null or empty, and prefer generating from a JSON Schema or OpenAPI spec when one exists.
Frequently asked questions
Interface or type — which should I choose?
For object shapes they are nearly interchangeable. Interfaces can be extended and merged by declaration and give slightly clearer error messages; type aliases can also express unions and mapped types. Many codebases pick one by lint rule — the toggle matches either convention.
How are optional fields detected?
From arrays of objects: if a key is missing in some items, it becomes optional. A single object cannot reveal optional fields, so every key is required unless you enable "null → optional".
Why is a field typed as null?
Because it was null in every sample item, so there is no other type to infer. Replace it with the real type (for example string | null) or paste a sample where the field has a value.
What happens to keys with dashes or spaces?
They are written in quotes, such as "content-type": string, which is valid TypeScript. Access them with bracket notation: obj["content-type"].
Does it validate data at runtime?
No — TypeScript types are erased at compile time. To check real responses at runtime, validate with a JSON Schema (see the JSON Schema Validator) or a library such as Zod.