Rates TodayNIFTY25,291.1+0.98%SENSEX82,104.8+1.23%Gold 24K ₹12,469.05/g down19.59Silver ₹152.90/g down3.38
InsightforGeeks

JSON to TypeScript Converter

Paste JSON and get ready-to-use TypeScript interfaces or type aliases. Nested objects become their own named types, arrays of objects are merged into one type, and keys that are missing from some items are marked optional. Everything runs in your browser, so your data is never uploaded.

How to use it

  1. Paste your JSON into the left box, or press “Load sample”. Invalid JSON is reported with the line and column.
  2. Set the name of the main type, and choose interface or type alias, export and readonly.
  3. Copy the TypeScript or download it as a .ts file.
  4. Check the result against your real API: a few sample records may not show every possible shape.

Frequently asked questions

How does the converter decide the types?

It looks at every value. Strings, numbers and booleans become string, number and boolean. For arrays it combines all the items, so a key that appears in only some of them becomes optional, and values of different kinds become a union such as string | number.

Why is a property typed as null or unknown?

A value that is null in your sample is typed as null, because the sample cannot show what else it might hold. If the real field can also be a string, change the type by hand, for example string | null. An empty array is typed unknown[] for the same reason.

What happens to keys such as user-id or 2fast?

Keys that are not valid TypeScript names are written in quotes, for example "user-id": string. Type names are built from the keys in PascalCase, and a number is added when two different shapes would have the same name.

Should I use interface or type?

For plain data shapes they behave almost the same. Interfaces can be extended and merged later, and type aliases can express unions. Pick whichever your project uses.

Is this a replacement for validating data?

No. TypeScript types exist only while you write and compile code and do not check data at run time. Use a validation library such as Zod on data that comes from outside your program.

Related tools

These tools run entirely in your browser and are provided free, without warranty. Check important results before using them in production.