go-supertools
Developer & Data Tools

JSON to TypeScript

Generate TypeScript interfaces or types from a sample JSON document.

Runs in your browser Your input never leaves your device.

Types are inferred from the sample you give. A property missing from some items of an array becomes optional (?); mixed values become unions. One sample cannot show which fields are really optional or what a number's range is, so review the result. Runs in your browser.

Report a problem with this tool

About this tool

Paste a sample of your JSON and the tool writes TypeScript declarations for it. Every nested object becomes its own named interface (the name comes from the property: an items array gives an Item interface), arrays of objects are merged into a single item type, and a property missing from some items becomes optional with a question mark. Values that differ become a union such as string | number | null, empty arrays become unknown[], and identical shapes are declared once and reused. Property names that are not valid identifiers, such as first-name, are quoted. You can choose interface or type, add export, mark everything readonly and name the root type. The output was checked against the real TypeScript compiler in strict mode. One sample cannot show which fields are really optional or what range a number has, so treat the result as a starting point and give the tool several array items to get optional fields right. Everything runs in your browser.

How to use it

  1. Paste a sample JSON document, ideally with several array items.
  2. Set the root name and choose interface or type.
  3. Tick export or readonly if you want them.
  4. Press Copy and paste the declarations into your project.

Common problems

A field is not marked optional
The sample had it in every item. Include an item where it is missing, or add the question mark yourself.
A type name ends in a number
Two different shapes had the same property name, so the second got a number. Rename them in your code.
The sample is a very large file
Very large or deeply nested JSON is refused with a message. Trim it to a representative sample.