JSON → TypeScript
Paste a JSON response and get interfaces that describe every item, not just the first
— keys some items lack become optional, null stays | null, mixed
values become unions, and nested objects get their own named types.
- Emits
- interface · type
- Handles
- optional · null · unions
- Runs
- in your browser
Your JSON
TypeScript types
How JSON values become TypeScript types
number — integers past 253 are flagged, because a number cannot hold them exactlystring with a // ISO 8601 date-time comment — JSON.parse never makes a Date"headquarters" becomes Headquarters"companies" becomes Company[]key?: Tkey: T | null — kept separate from optional(number | string | boolean)[]unknown[] · unknown · Record<string, unknown>"first-name": string — the key is never renamedWorth knowing
Every array item is read, not just the first
An array of objects becomes one type holding every key any item had. Keys only some items have are marked optional, so the compiler makes you check for them — instead of the first item's shape quietly claiming they are always there.
Missing and null are different
A key that is absent is key?: T; a key that is present with null is
key: T | null. APIs usually mean different things by the two, and with
strictNullChecks the difference is exactly what catches the bug.
interface or type
For object shapes they are interchangeable. Interfaces can be extended and merged and show
their name in error messages; type fits codebases that use aliases everywhere.
A top-level array or primitive is always a type alias, since an interface
cannot describe one.
Identical shapes share one type
billingAddress and shippingAddress with the same keys produce one
interface, used by both. Two different shapes that want the same name become
Item and Item2, and names that clash with built-ins such as
Response or Date get a Model suffix.
Types describe, they do not validate
These types are only as complete as the sample. A value that is sometimes a string in production but was always a number here will not be caught at runtime — pair them with a validator if the data comes from somewhere you do not control.
Nothing is uploaded
The JSON is parsed and the types are written by JavaScript in this tab. API responses often carry tokens and customer data, which is exactly what should not be pasted into someone else's server.