🔒 100% private — runs in your browser, nothing is uploaded

JSON to TypeScript

Infer TypeScript interfaces from real JSON records — merged across every sample, with optional fields, null unions and nested interfaces done properly.

Most JSON-to-TypeScript converters read one record and declare every key required and every type final — a fiction that breaks on the second real response. This one merges every record you paste before it decides anything. Worked example: pasting [{id: 1, name: "a", tag: "x"}, {id: 2, name: "b", extra: true}] produces an interface with id: number and name: string (present in both, so required), tag?: string (only in the first record, so optional) and extra?: boolean (only in the second, also optional). The same merging handles nulls — [{v: 1}, {v: null}] gives v: number | null — and nested objects, which are lifted into their own named interfaces: a user object under Root becomes interface RootUser, referenced as user: RootUser, so shared shapes stay shared instead of being inlined and drifting apart.

Your JSON stays in page memory on your device: it is never uploaded, stored or put into a link. Inference is only as good as the sample — a field that happens to be a string in every record you paste is typed as a string even if production data sometimes sends a number, so feed it varied, realistic records.

Quick answers

How do I convert JSON to TypeScript interfaces?

Paste an array of records and the tool merges them: keys in every record are required, keys missing from some become optional (tag?: string), keys that are sometimes null become unions (v: number | null), and nested objects become named interfaces such as RootUser.

Merging several real records is what makes the output trustworthy — a single-record conversion cannot see optionality, nulls or type variation at all.

How does the converter type arrays?

Element types are merged across every element of every record: ["a", "b"] gives string[], an array of objects gives a named interface array, mixed primitives give a bracketed union, and an array that is empty everywhere gives unknown[] — no element type was ever observed.

Feed it one non-empty example of each array and the precise element type replaces the unknown.

How to use

  1. Paste an array of JSON records — several real responses or rows, not just one. A single object also works and is treated as a one-record sample. The more varied the records, the more honest the types.
  2. Name the root interface (Root by default). Nested objects are named after it plus the field name, so a user object under Root becomes RootUser.
  3. Read the merge rules in the output: a key missing from some records is optional (tag?: string), a key that is sometimes null joins the union (v: number | null), and a key with different primitive types across records becomes a union of those types.
  4. Copy the interfaces into your project, then tighten them: inference sees only your sample, so rename the root, split anything the sample made too broad, and add the cases your sample happened not to contain.

About this tool

Arrays are merged the same way, element by element across all records: a field that holds ["a", "b"] in one record and numbers in another becomes a union element type in brackets, an array of objects becomes an array of a named interface, and an array that is empty in every record you have is honestly typed unknown[] — the tool cannot invent an element type it has never seen, and guessing string[] would be a lie your compiler would repeat. Two limits to keep in mind. Inference is bounded by the sample: a field that is always a string in your paste is typed string even if production occasionally sends a number, so paste varied, realistic, edge-case records. And field order and interface names follow the data, which makes the output a strong draft, not a finished design — review it the way you would review generated code from any source. Your JSON never leaves the page.

Frequently asked questions

Why merge multiple records instead of converting one?

Because one record cannot show optionality or variation. A key that appears in only some responses is optional, a key that is sometimes null is nullable, and a key whose type changes is a union — all three are invisible in a single sample and all three cause the runtime errors TypeScript exists to prevent. Merging is the whole point of this tool.

How are nested objects and arrays of objects named?

After the parent interface plus the field name in PascalCase: the object under user in Root becomes RootUser, and an array of objects under items becomes RootItems with the field typed items: RootItems[]. Every occurrence of that shape, in every record, merges into the one interface.

What does unknown[] mean in the output?

That every array seen for that field was empty, so there is no evidence about the element type. unknown[] is the honest answer: it forces a check at the point of use instead of asserting a type the data never demonstrated. Paste one record with a filled array and the real element type appears.

My JSON is a single object, not an array — does it still work?

Yes. A single object is treated as a sample of one record. Every key is required and no unions appear, which is exactly as trustworthy as a sample of one can be — paste more records whenever you can.

📦 Embed this tool on your site

<iframe src="https://verystep.com/embed/json-to-typescript/" title="JSON to TypeScript" width="100%" height="520" loading="lazy" style="border:0"></iframe>

Free to use. The embed shows a small "Powered by Verystep" link.

First time embedding? Read the step-by-step guide →

More free tools