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 What goes in A JSON sample
- 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 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.
More data tools
-
Data
JSON formatter
Format, minify, sort and validate JSON in your browser.
-
Data
CSV ⇄ JSON
Convert CSV to JSON and JSON to CSV in your browser.
-
Data
Unit converter
Type once and see every unit at once — length, weight, temperature, volume, speed, area and data.
-
Data
Tip calculator
Work out the tip and what each person owes, with the awkward rounding done for you.
-
Data
JSON to CSV
Paste an array of objects and get a spreadsheet-ready CSV, with the quoting and the awkward characters handled.
-
Data
Open a ZIP
See what a ZIP holds before opening it — how many files, how large, which are encrypted or escape their folder — then save what you want.
-
Data
Make a ZIP
Put any files into one compressed ZIP that opens on every system, accented names and all — stored as is where compressing would not help.
-
Data
Excel to CSV
Every sheet of an .xlsx becomes a CSV — values as the cells show them, dates as real dates, comma, semicolon or tab.
-
Data
CSV to Excel
One CSV makes a workbook, several make one workbook with a sheet each.