tigtools

JSON to TypeScript

Paste a JSON response or file and get TypeScript declarations you can drop into your code.

Runs in your browser No sign-up

Declare as

How to use it

  1. Paste JSON into the input box, open a .json file, or try the example.
  2. Set the name of the root type, for example Order or ApiResponse.
  3. Choose interface or type declarations and whether to add export and readonly.
  4. Copy the generated TypeScript or download it as types.ts.

How it works

The generator walks the whole JSON document and records the kinds of value found at each place. Each JSON object becomes its own named declaration. The name comes from the property key written in PascalCase, so “shipping_address” becomes ShippingAddress. Items of an array are named after the singular of the key: “items” gives Item, “categories” gives Category, and keys that do not look like plurals get an “Item” suffix.

All objects inside one array are merged into one interface. If a key appears in only some of them, it is marked optional with “?”. If a value has different kinds in different places, the type is a union such as string | number. null is kept as its own type, so a field that is sometimes null becomes string | null. An empty array becomes unknown[], because there is nothing to infer from. Two objects with exactly the same properties and types share one interface instead of producing duplicates. Keys that are not valid identifiers, such as “first-name”, are quoted.

The result describes only the sample you paste. A field that is optional or can be null in reality will be required and non-null if your sample does not show that, and dates arrive as plain strings. Review the types against your API documentation before relying on them.

Examples

Typing an API response

Paste an order from your shop API with the root name Order. You get interfaces Order, Customer, Item and Shipping, with note?: string on Item because only one of the two items has a note.

Read-only configuration

Paste a config.json, tick “Make properties readonly” and paste the result into config.d.ts, so accidental writes to the config are caught by the compiler.

Array at the top level

A list endpoint returns [{…}, {…}]. With the root name Product, the output starts with “export type Product = ProductItem[];” followed by the ProductItem interface.

Frequently asked questions

Why is a field optional in the output?

Because at least one object in the same array does not have that key. If every object has it, it is required. Paste several records to get more accurate optional fields.

Why is a date typed as string?

JSON has no date type, so dates travel as strings. The generator does not guess formats. Change the type yourself if your code converts them to Date objects.

What is the difference between interface and type?

For object shapes they work almost the same. Interfaces can be extended and merged by later declarations; type aliases cannot be reopened. Pick the style your codebase already uses.

Can it generate runtime validation such as Zod schemas?

No. It produces TypeScript declarations only, which are checked at compile time and do not validate data at runtime.

Privacy

Your JSON is analysed only in your browser. Nothing is uploaded, stored or included in analytics.