Skip to content

Menu

JSON to TypeScript

Convert JSON objects to TypeScript interfaces and types with nested object support.

Runs entirely in your browserAIFree, no sign-up
Loading tool

01What is JSON to TypeScript?

Hand-writing interfaces for a 200-line API response is slow and easy to get wrong. Paste a JSON sample here and you get TypeScript types back as you type, ready to copy into your project. The tool parses your input with the browser's own JSON.parse, so it follows the JSON grammar in RFC 8259. Trailing commas, comments and single quotes are rejected, and you see the parser's exact error message instead of a guess. Nothing is sent to a server. Once parsed, it walks the value and builds a shape for every key. Objects become exported interfaces. Nested objects get their own interface, named in PascalCase after the key that holds them. Arrays become an element type followed by []. Arrays of objects are where it earns its keep. Every element is merged into one interface. A key that shows up in only some elements is marked optional with ?. A key that holds different kinds of values becomes a union, such as string | null. Mixed primitive arrays become a union array like (string | number | null)[]. An empty array becomes unknown[], because there is nothing to infer from. Naming follows a few simple rules. Array item types use the singular of the key, so "users" gives User and "categories" gives Category. When no singular can be guessed, Item is appended. Keys that aren't valid identifiers, like "user-id" or "2fa", are written as quoted string keys, so the type still matches your data. A name that would shadow a built-in such as Promise or String gets a Type suffix, and duplicate names are numbered. Here is a quick example. Paste {"rows":[{"v":"a"},{"v":null}]} and you get a Root interface with rows: Row[], plus a Row interface where v is string | null. If the root of your JSON is an array, you get a type alias instead, such as export type Item = ItemItem[];. Some limits are worth knowing. All numbers become number, since JSON doesn't separate integers from decimals. A field that is only ever null in your sample is typed as plain null. A field that is always present in the sample is never marked optional, even if your API sometimes leaves it out. Strings that hold dates or IDs stay string. The output is a starting point, so read it against the API docs before you trust it.

TypeScript developers who need typed models for an API response, webhook or config file and would rather not write the interfaces by hand. The tool runs entirely in your browser, so your data never leaves your device.

02How to use JSON to TypeScript

  1. Paste a JSON object or array into JSON Input, or load one of the three examples
  2. Set the root name; it becomes the name of the top-level interface or type alias
  3. Read the generated interfaces in the output panel; errors in the JSON appear below
  4. Click Copy and paste the types into your project

03Worked examples

Input: {"id":1,"name":"Ada","email":null} (root name User)
Result: export interface User { id: number; name: string; email: null; }
A field that is only ever null is typed null; paste a sample where it has a value to get a useful type.
Input: {"users":[{"id":1,"tags":["a"]},{"id":2,"nickname":"bo"}]}
Result: export interface Root { users: User[]; } export interface User { id: number; tags?: string[]; nickname?: string; }
Array items are merged; keys missing from some items become optional, and the item type is named from the singular of "users".
Input: [{"price":9.99},{"price":10}] (root name Item)
Result: export type Item = ItemItem[]; export interface ItemItem { price: number; }
Input: {"user-id":"x","2fa":true,"apiURL":"https://x"}
Result: export interface Root { "user-id": string; "2fa": boolean; apiURL: string; }
Keys that aren't valid identifiers are quoted instead of renamed, so the type still matches the JSON.
Input: {"rows":[{"v":"a"},{"v":null}]}
Result: export interface Root { rows: Row[]; } export interface Row { v: string | null; }
When items disagree on a value's kind, the key becomes a union instead of optional.
Input: {"vals":[1,"a",null],"status":"ok"} (root name Promise)
Result: export interface PromiseType { vals: (string | number | null)[]; status: string; }
Promise is a built-in name, so the root gets a Type suffix. Mixed array items become a parenthesised union array.

04Common use cases

  • Typing a fetch() call from a real API response you copied out of the browser's network tab
  • Writing interfaces for a JSON config file that a Node or Deno service loads at startup
  • Turning a webhook payload sample from a provider's docs into types before writing the handler
  • Typing a paginated list endpoint where some items carry extra keys, so you can see which ones should be optional
  • Giving a frontend teammate shared types for a mock JSON fixture while the real backend is still being built
  • Spotting inconsistent data: a union like string | number on an ID field tells you the API isn't returning one type

05Tips

  • Paste an array with several representative items rather than one; the more variety the sample has, the more accurate the optional fields and unions will be.
  • A sample can only show what it contains. A field that is always present in your sample but can be missing in production will not be marked optional, so review against the API's documentation.
  • IDs that look numeric but can have leading zeros or exceed Number.MAX_SAFE_INTEGER are better typed as string; change those by hand.
  • Generated types describe data but don't check it at runtime; pair them with a validator such as Zod if the data comes from outside your code.

06Related concepts

TypeScript interfaces, Type inference, Union types, Optional properties, JSON.

Frequently Asked Questions

What is JSON to TypeScript?

JSON to TypeScript is a free, browser-based developer tool on AIDToolStack. Convert JSON objects to TypeScript interfaces and types with nested object support. It requires no installation or sign-up and works entirely in your browser.

Is JSON to TypeScript free to use?

Yes. No sign-up, no fees and no usage cap.

Does JSON to TypeScript store my data?

No. It runs in your browser; nothing is uploaded.

Cheat sheet

Related Tools

Reviews and commentsShow

Reviews

Sign in to leave a review.

Loading reviews…

Comments

Sign in to leave a comment.

Loading comments…

What changed in AI dev tools, once a month

Renames, shutdowns, pricing changes and new MCP setups, each with a source.

Subscribe