Developer tool
JSON to TypeScript Converter
Free, no sign-up. Runs in your browser; nothing is uploaded.
Options
JSON
TypeScript
The result appears here.
How to use the json to typescript converter
Turn a sample response into types
- Paste a JSON document, or press Sample to see an example. The TypeScript appears as you type.
- Set the root name. The top-level type uses it, and nested objects are named after their keys, so a key called
addressbecomes anAddresstype. - Choose interface or type, and decide whether to add
exportandreadonly. - Copy the result or download it as a
.tsfile.
How the types are worked out
- Strings, numbers and booleans map to
string,numberandboolean. - Arrays are merged: the tool reads every item and builds one element type. Objects of the same shape collapse into a single type, and keys that appear in only some items become optional.
- Mixed values produce a union such as
string | number. Anullis placed last, so you seestring | null. - An empty array has no evidence about its contents, so it becomes
unknown[]. - Keys that are not valid identifiers, such as
first-name, are quoted.
Tips for better results
- Paste the largest, most varied response you have. More items mean better optional and union detection.
- If a field is sometimes an object and sometimes missing, include one example of each.
- Rename generic names such as
Item2once you have copied the output. The tool adds a number when two different shapes share a name. - For API contracts that change often, treat the output as a starting point and add runtime validation for data you do not control.
- IDs larger than 2^53 lose precision when parsed as JSON numbers. If your API returns long numeric IDs, change those fields to
stringby hand.
Frequently asked questions
How does it decide that a property is optional?
When the JSON holds an array of objects, the tool merges every item. A key that is missing from at least one item is marked optional with a question mark. A key that is present everywhere but holds null in some items becomes a union with null instead.
Why do I get a union type for some properties?
If the same key holds different kinds of values across array items, for example a number in one and a string in another, the type is the union of both. Review those cases: they often point at inconsistent data from the API.
Should I use interface or type?
Both describe object shapes. Interfaces can be extended and merged, and give slightly clearer error messages. Type aliases work for unions and tuples too. Pick the style your project already uses.
Is the generated type a guarantee?
No. It describes the sample you pasted, so a rarely present field may be missing. Feed it several real responses, or validate at runtime with a schema library, before trusting it for production data.
Is my JSON sent anywhere?
No. The conversion runs in your browser, so tokens, customer data and internal API responses stay on your device.