JSON to TypeScript Converter

What is JSON to TypeScript Converter

This tool turns any JSON into clean TypeScript interfaces, right in your browser. It walks the whole structure, creates a named interface for every nested object, infers the type of each field, and types arrays from their contents. When objects in an array do not all share the same keys, the missing ones are marked optional so the result compiles against real-world data.

How to use

  1. Paste your JSON into the input field on the left.
  2. Name the root interface if you want something other than Root.
  3. Read the generated TypeScript on the right, updated as you type.
  4. Click Copy and drop the interfaces straight into your code.

When to use it

Got a JSON response from an API and no types for it? Paste it in and you get ready-to-use interfaces in seconds. Feed it a list of users where one record is missing an avatar field and the converter marks that field optional (avatar?: string), so your types match what the endpoint actually returns instead of a guess.

Frequently asked questions

How are optional fields detected?

When you paste an array of objects, the converter compares the keys across every item. Any key that is not present in all of them becomes optional (marked with ?). Keys present in every item stay required.

Does my JSON get sent to a server?

No. The whole conversion runs in your browser with JavaScript. Nothing is uploaded, so private API payloads and internal data never leave your machine.

How does it handle nested objects and arrays?

Each nested object becomes its own named interface, derived from the key name. Arrays are typed from their items: number[], a merged interface for arrays of objects, or a union like (string | number)[] for mixed content.

What happens with null or empty arrays?

A null value is typed as null and an empty array becomes any[], since there is no sample to infer an element type from. Fill in a representative example to get a precise type.

Can I share this tool with my JSON pre-filled?

Yes. The URL updates automatically as you type. Copy it from the address bar or use the Copy link button, and anyone who opens the link sees your exact JSON already converted.

Related tools