How to use this JSON to TypeScript converter
Paste a JSON document — ideally a real response from the API you are about to consume — set the root type name, and press “Generate TypeScript”. The converter walks the whole structure and writes an interface for every object it finds. Primitive values become string, number, boolean or null; arrays take the type of their contents, so a list of strings becomes string[] and a list of objects becomes an array of a named interface generated from those objects. Nested objects are named after the key that holds them, in PascalCase, so the object under "address" becomes the interface Address.
The clever part is what happens when the top level — or any array — holds several objects. The generator compares them key by key. Keys present in every item stay required; a key missing from even one item is marked optional with a question mark, because your own sample demonstrates it cannot be relied on. If the same key holds different types in different items, the field becomes a union of those types. When the root itself is an array of objects, you get the item interface plus a type alias such as export type Users = User[];.
Use the richest sample you have. The output can only describe the data it has seen: a field an API sends only on Tuesdays will not appear if your sample was captured on a Monday, and a value that happens to be null in this response will be typed null even if it is usually a string. Generate from a complete, realistic payload, then read the result once with a developer's eye before pasting it into your project — that review takes a minute and is the difference between types that help and types that merely look helpful.
Example: from sample JSON to interfaces
The pre-filled sample — a name, an age and a nested address — generates:
Load the bigger sample and you will also see an array of project objects become a Project interface, with its published field marked optional — because one of the two sample projects has that field and the other does not. That single question mark, inferred from evidence, is the sort of detail that saves a runtime bug later.
Why bother typing JSON at all?
An untyped API response is a bag of surprises: every property access is a guess, every rename is a hazard, and the first sign of a changed field is a production error. Interfaces flip that around. The editor autocompletes field names, the compiler flags the property you misremembered, and when the API changes its shape, the type errors point at exactly the code that assumed the old shape. Generating the first version from a real sample removes the tedious, error-prone part — typing out forty field names by hand and inevitably misreading two of them — and leaves you the interesting part: deciding what the types should promise.
The honest limits of inference
Inference from a sample is evidence, not truth, and three limits are worth keeping in mind. First, numbers: JSON cannot distinguish an integer from a decimal, so everything numeric is number, even IDs you might prefer as a branded type. Second, strings with hidden structure — dates, UUIDs, email addresses — are just string until your code gives them meaning. Third, enums: a status field that reads "active" in the sample becomes string, not the union "active" | "paused" | "closed" the API really uses, because one sample cannot prove the full set. Generate, then tighten the handful of fields where you know more than the sample does. That combination — machine breadth plus human judgement — is how most production type definitions are actually born.
Frequently asked questions
How does the generator name the interfaces?
Interface names come from the keys that hold the objects, converted to PascalCase: an object under the key “address” becomes the interface Address. For an array of objects the key is singularised first, so “projects” yields Project. If two different shapes would take the same name, the later one gets a number suffix instead of silently merging.
What does an optional field (with a ?) mean here?
When the JSON is an array of objects, the generator compares every item. A key that appears in some items but not others is marked optional — published?: boolean — because your sample itself proves the field is not always present. Fields present in every item stay required.
How are mixed arrays handled?
If an array contains values of more than one type, the field becomes a union: (string | number)[] for a list mixing strings and numbers. An empty array has no evidence to infer from, so it is typed unknown[] — a deliberate prompt to decide the element type yourself.
Will a date string become a Date type?
No. JSON has no date type, so “2026-12-03” is a string in the data and string in the interface. Typing it as Date would be wrong: a parsed JSON value is never a Date object until your code converts it. If you plan to convert, change the field type by hand after generating.
Can I rename the root interface?
Yes — the root name field sets it. If the JSON is a single object, that name becomes the root interface. If the JSON is an array of objects, the name becomes a type alias for an array of the item interface, for example export type Users = User[].
Are the generated types guaranteed correct?
They are an honest inference from the one sample you paste — no more, no less. A field that happens to be null in your sample is typed null, and a field the API only sometimes sends will be missing entirely if this sample lacks it. Treat the output as a strong first draft: generate from the richest, most complete sample you have, then review.
What happens with keys that are not valid identifiers?
Keys containing spaces or starting with digits cannot be written bare in TypeScript, so the generator quotes them — "first name": string — which is valid TypeScript and matches the JSON exactly. Ordinary keys are emitted unquoted.
Is my JSON uploaded anywhere?
No. The inference runs in JavaScript in your browser. Sample payloads often come from private or pre-release APIs; here they never leave your device, and the tool works offline once the page has loaded.
Should I use interface or type for API data?
For plain object shapes like API responses, interface and type are effectively interchangeable, and interface is the common convention this generator follows. Reach for type when you need unions, tuples or mapped types — you can always convert a generated interface later without changing how your code uses it.