About the JSON to TypeScript Converter
Typing an API response by hand is slow and easy to get wrong. Paste a sample of the JSON and this converter writes the TypeScript for you. It names nested objects after their keys, turns arrays into typed lists, makes unions where values differ and marks fields as optional when they are missing from some objects in an array. Choose interface or type alias, add export, and mark properties as readonly. The result is a good first draft that you can paste into your project. It only sees your sample, so check it against the real API. Everything runs in your browser, so private data is not uploaded.
Updated October 2026
How to use the JSON to TypeScript Converter
- 1Paste a sample of your JSON on the left.
- 2Type the name for the main type.
- 3Choose interface or type alias, and the export and readonly options.
- 4Read the generated TypeScript on the right.
- 5Copy it into your project and adjust names or optional fields.
From sample to types
A good sample matters more than anything else. Include a full example of every object shape, including optional fields and values that can be null. If your API returns a list, paste several items so the converter can see which fields are always present and which come and go.
The tool merges items of the same array into one type. A field that is a number in one item and a string in another becomes number | string, a warning sign that the API is inconsistent or that you need a closer look.
The converter is careful with edge cases. Keys that are not valid names, such as first-name, are quoted. A property that is null in your sample is typed as null, so widen it to string | null yourself if the real API can return text there. Top-level arrays and plain values are also supported and produce a single alias.
After you paste the result
- Rename types that clash with names in your project.
- Replace string with a union of literals for known values, such as "open" | "closed".
- Change numbers that hold timestamps to a clear alias.
- Add runtime validation if the data comes from users.
- Keep the original sample next to the types for future checks.
Related tools
For a validation file rather than types, use the JSON Schema Generator. Check that your sample is valid with the JSON Validator, tidy it with the JSON Formatter, and test queries on it in the JSON Path Tester. If your data starts as a table, the CSV to JSON Converter is a good first step.
Features
- Interfaces or type aliases
- Nested objects get their own named types
- Arrays merged into one item type
- Optional fields when objects differ
- Unions for mixed values
- Export and readonly options
- Private, runs in your browser
Frequently asked questions
How does the converter pick types?
It looks at each value: strings, numbers and booleans become string, number and boolean; null becomes null; arrays and objects are inspected recursively.
How are optional fields decided?
If several objects in an array share a shape but one lacks a key, that key is marked optional with a question mark.
What about numbers that are really dates or ids?
A date string is still typed as string. Refine the types yourself, for example with a Date or a branded id type.
Why is a field typed as unknown[]?
An empty array gives no hint about its items, so the converter uses unknown. Replace it with the right type.
Should I use interface or type?
Both work for plain data. Interfaces can be extended and merged, while type aliases also describe unions. Pick one style and be consistent.
Can it handle keys like first-name?
Yes. Keys that are not valid identifiers are quoted in the output, such as "first-name": string.
Is the generated type guaranteed to match the API?
No. It describes your sample only. Validate real responses at runtime if the data comes from outside your control.