Tools · TypeScript

JSON to TypeScript

The same data, written as the types a client would want — one interface per object, nested, from the response you already have.

no signup · runs entirely in your browser · ⌘V works anywhere on this page
See it done · 10 s
JSON to TypeScript — The response as a tree, Convert, TypeScript: one interface per object, arrays typed from every element. · 10 s

What you get

  • Writes the API-response sample as 7 interfaces in 54 lines
  • Gives each nested object its own interface, named from its key
  • Types an array from every element, not the first: the paginated list's 3 interfaces mark failure_message optional, because two of three charges lack it
  • Keeps null as null; a field that is sometimes null is a union — failure_code: string | null
  • Names the root after the file: clean-order-example.json → CleanOrderExample

What it will not do

  • Write Zod, JSON Schema or io-ts. Interfaces only.
  • Infer formats. A date string is a string, an id is a string — it types what is there.
  • Send your text anywhere. The page is static and the engine runs in this tab — open the network panel and watch it stay empty.

What you get

An object → an interface, named from the file
{"id": 1, "status": "paid"}export interface Order { id: number; status: string; }
A key missing in some items → optional
[{"id":1,"note":"x"},{"id":2}]export type Order = OrderItem[]; export interface OrderItem { id: number; note?: string; }
null in some items → a union
[{"id":1,"ship":null},{"id":2,"ship":"air"}]export type Order = OrderItem[]; export interface OrderItem { id: number; ship: string | null; }
A list of objects → its own interface, and an array of it
{"items":[{"sku":"A","qty":1}]}export interface Order { items: Item[]; } export interface Item { sku: string; qty: number; }

The sample

What the first sample opens — a real file, not an illustration written for this page.

clean-order-example.json → TypeScript, as Convert writes it
export interface CleanOrderExample {
  order_id: string;
  created_at: string;
  status: string;
  customer: Customer;
  items: Item[];
  shipping: Shipping;
  totals: Totals;
  metadata: Metadata;
}

export interface Customer {
…

in VS Code

Generate TypeScript interfaces from the command palette; Convert, then TypeScript, does the same into a new editor.

unstringify for VS Code14-day trial · Free and Pro

Questions

Does it handle nested objects and arrays of objects?

Yes: each nested object becomes its own interface, and an array of objects is typed from all of its elements.

What happens when a field is null?

It is typed null. When another element has a value there, the field is a union of the two.

Can I type just one branch?

Yes — focus it in the tree (f), and Convert acts on that branch instead of the file.

Is the output deterministic?

Yes. The same JSON gives the same interfaces every time; there is no model involved.

Try it on the file that broke your afternoon.

free · no signup