UtilDojo

Popular

Menu

JSON to TypeScript Interface Converter

  • This tool runs entirely in your browser. Nothing you enter or upload is sent to a server.

JSON sample

Tab indents · Shift+Tab outdents · Esc then Tab moves on

TypeScript

Your TypeScript shows up here

Paste or type on the left, upload a file, or drop one onto the input.

Waiting for input

JSON & data

About this tool

Paste a JSON sample — an API response works best — and get ready-to-use TypeScript declarations. Nested objects become their own named interfaces, and arrays of objects are merged so fields missing from some items are marked optional.

Choose between interface and type alias output, rename the root type, and decide whether null values should become optional properties. As an example, a user object with id, name, an address object and an orders array becomes export interface User, export interface Address and export interface Order, with the root declared first. The names come from the key (orders gives Order, using a simple singular rule), and a clashing name gets a number suffix such as Address2. Property names that are not valid identifiers are quoted.

If one order has "coupon": null and another has no coupon at all, the generated Order has coupon?: null. The merge works the same for types: a field that is a number in one item and a string in another becomes number | string. Whole numbers and decimals are both typed as number, and an empty array becomes unknown[] because there is nothing to learn from it.

Generated types are a starting point: review unions and optional fields against your real API contract before shipping. A sample cannot reveal that a field can sometimes be absent, or that a string is really one of a few allowed values, so give the tool a richer sample, or several items in one array, to get better output. The conversion runs in your browser and the JSON is not uploaded.

Frequently asked questions

How are arrays with different object shapes handled?

All items are merged into one shape. A field present in only some items becomes optional, and fields with different types become a union.

Should I use interface or type?

Both work for object shapes. Interfaces can be extended and merged; type aliases are more flexible for unions. Pick whichever your codebase uses.

Is the JSON sent to a server?

No. Type generation runs entirely in your browser.

What does the “null → optional” option do?

With it on, a field that is null in the sample is written as an optional property, for example `coupon?: null`. Turn it off to keep a required property whose type includes null.

Can it generate types from a top-level array?

Yes. If the JSON is an array of objects, they are merged into one item type and the root is declared as an array of that type.

What happens to a sample with a string that looks like a date?

It stays a plain `string`, since TypeScript has no date-string type. The Zod generator is the one that detects dates, emails and UUIDs.

Related tools