JSON to TypeScript Interface Generator
Generate TypeScript interfaces from JSON automatically, including optional fields and nested types. Save hours of manual typing with our free JSON to TypeScript converter.
How it works
Paste JSON into the left editor, or click Sample JSON to load an example. Set the name you want for the root type (it defaults to Root), then press Generate Interface. The TypeScript appears on the right, ready to copy or download as types.ts. Parsing and generation happen in your browser, so your JSON is not sent to a server.
The generator reads each value and picks a type for it.
- Primitives become string, number or boolean. Integers and decimals are both number.
- Nested objects get their own interface, named after the parent plus the key. A
metadatakey insideRootproducesRootMetadata. - Arrays of primitives become
string[]ornumber[]. Mixed primitive arrays become a union such as(string | number)[]. Empty arrays becomeunknown[]. - Arrays of objects produce an item interface, such as
RootUsersItem[]. - Keys that are not valid identifiers, like
user-name, are wrapped in quotes.
The Use type instead of interface checkbox switches the output from interface Name { } to type Name { } declarations.
When this is useful
The usual case is typing an API response. You call an endpoint, copy the JSON from your browser tools or a curl command, and need a first draft of the types before writing the fetch code. It saves the repetitive part of typing out every field.
It also helps when you inherit a config file, a fixture or a webhook payload and want to see its shape written down. Treat the output as a starting point and review it before committing it.
What to know before you use the output
A single JSON sample cannot tell you everything about an API. The tool only sees the data you give it, which leads to a few limits.
- If the top level is an array, only the first element is used to build the type. If later items have extra or missing keys, they will not show up.
- The same applies to arrays of objects inside the data: the item interface comes from the first item only.
- A property is marked optional only when its sample value is null. Fields that are sometimes missing in real responses will come out as required, and null values are typed as
null, not as a union with the real type. Edit these by hand where you know better. - Nested objects inside an array item's own arrays and mixed arrays that contain objects are typed loosely, so check them.
- Dates and IDs arrive as plain strings in JSON, so they are typed as string. Narrow them yourself if you need a stricter type.
- A top-level primitive, such as a bare string or number, is not a valid object type, so check the result if you try one.
For the best result, paste a sample that includes every field you expect, with realistic values rather than nulls.
Frequently asked questions
Should I use interface or type?
For plain object shapes the two behave almost the same. Interfaces can be extended and merged, while type aliases are needed for unions. Pick whichever your codebase already uses.
Why is my JSON rejected?
The input must be valid JSON: double-quoted keys and strings, no trailing commas, no comments. The error message shows what the parser found. The JSON Formatter on this site can help locate the problem.
Is my data private?
Yes. Conversion runs locally in your browser and nothing is uploaded.
Does it validate data at runtime?
No. TypeScript types disappear at compile time. If you need to check incoming data, pair the types with a runtime validator or a JSON Schema check.