DFK Studio

Turn JSON into TypeScript types

Paste JSON and get TypeScript interfaces back, with nested objects named, array element types unified and optional keys marked. Runs in your browser.

  • Free, no account
  • Nothing is uploaded
  • Runs in your browser

How it works

  1. 1 What goes in A JSON sample
  2. 2 It runs in your browser On your own device. Nothing is uploaded, there is no queue and no account, and it keeps working with the network switched off.
  3. 3 What comes back TypeScript types that describe it

What it does

Paste a response body and get types you can paste into an editor. Nested objects become their own named interfaces, arrays are unified across their elements, and a key missing from some elements is marked optional rather than guessed at.

This page does the work itself. Your JSON is handled by the browser and never sent anywhere — there is no server here to send it to.

Questions

How are optional keys decided?

By looking across every element of an array. If a key appears on some objects and not others, it is marked optional; if it is present everywhere but sometimes null, the type gets | null instead. One sample object cannot tell you either of those things, which is why pasting the whole array gives much better types than pasting one item from it.

Why is an empty array typed unknown[]?

Because nothing in the sample says what goes in it. Guessing any[] there would silently switch off type checking at exactly the point where the data is least known. unknown[] makes the gap visible and takes one edit to fix.

Does it handle a JSON response with numbers that are really IDs?

It types them as number, because that is what the JSON says. Large IDs that arrive as JSON numbers are worth a second look regardless of this page: anything past 2^53 has already lost precision by the time JSON.parse returns it, which is why well-behaved APIs send them as strings.

Every shelf