Skip to content
Jellykit

JSON to TypeScript

Generate TypeScript interfaces or type aliases from a JSON sample, with array items merged and missing keys made optional.

  • Runs on your device
Loading tool

About JSON to TypeScript

Paste an API response or a config file and get TypeScript declarations for it: one interface for every distinct object, named after the key it sits under, so items in an "orders" array become an Order.

When an array holds objects of slightly different shapes, they are merged into one type, and a key that only some of them have is marked optional. Values that are sometimes null become "T | null", and mixed arrays become unions. Choose interfaces or type aliases, a name for the root type, and read-only properties if you want them.

How it works

  1. The JSON is parsed by the browser and every value is reduced to its kind: string, number, boolean, null, array or object.
  2. The items of each array are merged into one shape. Keys present in only some items become optional, and different kinds become a union such as "string | number".
  3. Each distinct object shape becomes a declaration named after its key, singular for array items. Shapes that are identical share one declaration.
  4. Names that would hide a built-in type such as Date get a suffix, and keys that are not plain identifiers are quoted.

Questions

How does it decide that a field is optional?

Only from your sample. A key is optional when some objects in the same array have it and others do not. If every sample object has a key, the tool cannot know it might be missing, so include varied examples when you can.

Why is a date typed as string?

JSON has no date type: a date arrives as text, and it is still a string until your code converts it. The same goes for ids written as text.

What does unknown[] mean in the result?

The array was empty in your sample, so there was nothing to infer its items from. Replace unknown with the real item type, or paste a sample where the array has content.

Is there a size limit?

Samples up to 2 MB, nested up to 256 levels. A few representative records give the same result as thousands, and the JSON never leaves your device.

Everything you enter here is processed in this browser tab. Nothing is uploaded, logged or shared. How privacy works here.