TypeScript Interfaces from JSON
Infer a draft of types from a JSON sample, and state that it depends on the sample and needs review.
Nested objects get their own named type. Items of a list are merged, and a key missing from some items becomes optional (?). The types come from this one sample, so check them against your real data.
Your result
Paste a JSON sample and the TypeScript types appear here.
How to use it
- Paste JSON or press Try a sample.
- Type the root type name and choose interface or type.
- Copy the declarations or download them as a .ts file.
Examples
- A simple object{"id": 1, "name": "Ada"} export interface Root { id: number; name: string; }
- An optional field[{"a": 1}, {"a": 2, "b": true}] b?: boolean
- A mixed list[1, "a"] (string | number)[]
Tool details and privacy
Paste a JSON example (such as an API response) and get ready TypeScript declarations: a root type with the name you choose and a separate type for each nested object.
Typing a long API response by hand is slow, and a mistake shows up as a runtime error.
Options
- Each nested object is named from its key, such as address → Address and products → Product.
- List items are merged, and a key missing from some of them becomes optional (?).
- Keys that are not valid names, such as "first-name", are quoted.
Limits
- The types come from this one sample: a null field becomes null only, and an empty list unknown[].
- Dates and fixed sets of values (enums) are not inferred from text.
Privacy
What you type stays in your browser. Nothing is uploaded or saved on the server.
Questions
Why is email typed null?
It is null in the sample. Change it to string | null if it sometimes holds text.
What is the difference between interface and type here?
The same shape; pick what your project uses.
Do Arabic keys work?
Yes, written as is, since they are valid TypeScript names.
Is the JSON uploaded?
No.