1001Ferramentas
🅃 Converters

JSON to TypeScript

Convert a JSON to TypeScript interfaces with automatically inferred types. Detects strings, numbers, booleans, arrays, nested objects and union types. Everything in your browser.

Como funciona?

O conversor lê seu JSON e infere o tipo TypeScript correspondente para cada campo: string, number, boolean, null, arrays e objetos aninhados (cada um vira uma interface separada). Quando um array tem itens de tipos diferentes, é gerada uma união ((string | number)[]).

Útil para gerar tipos a partir de respostas de APIs reais, payloads de webhooks ou estruturas de dados que você acabou de receber. Tudo roda no seu navegador — nada é enviado a servidores.

Generate TypeScript interfaces from JSON

Typing an API response in TypeScript pays off. Writing those interfaces by hand from a big JSON, though, is tedious and easy to botch. Paste your JSON here and the matching interfaces come out automatically, with the types already inferred.

It recognises strings, numbers, booleans, arrays and nested objects, and when values vary it builds type unions too, so the result mirrors the shape of your data. Within seconds you've got code ready to drop into the project, which saves the manual grind and cuts down on typos.

Your JSON never leaves your device, because the whole conversion happens in the browser. Paste the data, copy the interfaces, and your code ends up with strong typing.

Frequently asked questions

Why did an array of objects produce two identical interfaces, Post and Post2?
Because every item in the array is inspected on its own. The converter never compares shapes to notice they match, so two objects inside posts become two interfaces, Post and Post2, and the field ends up as posts: (Post | Post2)[]. When the two really are identical, delete the second one and swap the union for Post[]. When they differ, what you are looking at is a map of exactly which fields vary between items, usually worth reading before you delete anything.
One field came out typed as null. How do I fix that?
That is the ceiling of inferring types from a single sample. If the field sits at null in the JSON you pasted, there is no way to know what it holds when filled, so the output is literally deletedAt: null. Replace it by hand with the real union, string | null for instance. Same reasoning elsewhere: an empty array becomes unknown[], a date in text form comes out as string, and no field is ever marked optional, so a key missing from the sample vanishes from the interface instead of turning into an optional one.
What does the root interface name field do when the JSON starts with a bracket?
It names two things at once. With an array at the root, the name you type becomes the list type while its singular form names the item interface: typing Users yields interface User alongside type Users = User[]. The name is run through PascalCase first, so my response turns into MyResponse. If the JSON is a bare value such as 42 or a string, the output is a type rather than an interface. The checkbox next to the field strips export from every block at once.

Related Tools