- Home
- Free Tools
- JSON to TypeScript
JSON to TypeScript
Paste a JSON sample and get clean TypeScript interfaces back. Optional keys, unions and nested types are all inferred, and your data stays in the browser.
JSON
TypeScript
Your interfaces will appear here.
What you can do
- Type an undocumented API. Paste a real response and get a starting point in seconds instead of hand-writing every field.
- Find the optional fields. Paste several records and the merge tells you which keys are actually guaranteed.
- Keep nested shapes readable. Objects become their own named interfaces rather than one deeply indented blob.
- Match your house style. Interfaces or type aliases, tabs or spaces,
T[]orArray<T>, readonly or not.
One sample is not enough
The most common way generated types go wrong is inferring from a single record. Every key that record happened to include comes out required, and the first response that omits one produces a runtime error your compiler promised could not happen. Paste an array of several records — ideally including an edge case or two — and the optional keys reveal themselves.
Frequently asked questions
Is my JSON uploaded anywhere?
No. Everything is inferred in your browser, which matters because the JSON you want types for is usually a real API response — often one containing production data or an access token you would rather not paste into someone else’s server.
How does it decide which keys are optional?
By comparing records. When an array holds several objects, they are merged field by field: a key present in every object stays required, and a key missing from any of them becomes optional. This is why you should paste several records rather than one — a single sample cannot tell the difference between a required field and one that merely happened to be present.
What happens to null values?
A null becomes the null type, so a field seen as both a string and a null is typed string | null. That is usually what you want from an API, where null genuinely is a value the endpoint returns. It is not the same as an optional key, and the tool keeps the two distinct.
Where do the interface names come from?
From the property the object sits under, converted to PascalCase. A property holding a list is singularised first, so items produces an Item interface rather than an Items one. If two different objects would claim the same name, the second gets a numeric suffix.
What about keys that are not valid identifiers?
Keys such as first-name or 2024 are emitted as quoted string literals, which is valid TypeScript and keeps the type an accurate description of the data. Nothing is renamed, because a renamed key would no longer match the JSON at runtime.
Why is my empty array typed unknown[]?
Because an empty array carries no information about what it holds. unknown[] is the honest answer and forces you to narrow it deliberately. Include a sample with at least one element and the real element type is inferred instead.
Does this validate at runtime?
No, and no generator can. TypeScript types vanish at compile time, so they describe what you believe the API returns, not what it actually sent. For untrusted input, pair these interfaces with a runtime validator such as Zod or Valibot — the generated types are a good starting point for writing that schema.
Building on someone else's API?
AgileTechForge builds the integrations that sit between systems that were never designed to talk to each other — and keeps them working when the other end changes.
Talk to our team