Skip to content
Browse tools

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
Step 1

Your JSON

empty
drop a .json file to load it
Step 2

TypeScript types

Declare
Arrays
Options
empty
Nothing to convert yet Paste JSON on the left, open a .json file, or load the sample.

How JSON values become TypeScript types

In the JSONIn the TypeScript
42 · 4.5number — integers past 253 are flagged, because a number cannot hold them exactly
"2025-11-02T09:30:00Z"string with a // ISO 8601 date-time comment — JSON.parse never makes a Date
{ … }A named interface: "headquarters" becomes Headquarters
[ { … }, { … } ]One merged, singularised type: "companies" becomes Company[]
key missing in some itemskey?: T
null in some itemskey: T | null — kept separate from optional
[1, "two", true](number | string | boolean)[]
[] · only ever null · {}unknown[] · unknown · Record<string, unknown>
"first-name"Quoted: "first-name": string — the key is never renamed

Worth 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.