Shard Tools

JSON to TypeScript

Generate TypeScript interfaces from a JSON sample in your browser.

Maintained by Roshan.

Use JSON to TypeScript

Converts json sample to typescript in this tab, with nothing sent anywhere.

Runs entirely on your deviceThe conversion happens in this browser tab. Nothing you type is uploaded, logged or stored, which is worth knowing for anything you would not paste into a search box.

Explore generators

Find related browser-local tools for nearby tasks without starting another search.

Browse all generators

About JSON to TypeScript

Writing a TypeScript interface by hand from a real API response is tedious and easy to get subtly wrong - a mistyped field, a missed nesting, a number where a string should be. Generating it from an actual sample removes the guesswork: paste the JSON your API really returns, and get the interface that matches it. This infers the shape recursively, so a nested object becomes its own named interface rather than an inline blob, which is how you would write it by hand and what keeps the types readable. The inference is deliberately conservative - it describes exactly what the sample contains and does not invent optional fields or unions a single example cannot prove - so the output is an accurate starting point you refine, not a guess dressed up as certainty.

Using JSON to TypeScript

  1. The JSON is parsed and its structure inferred recursively, field by field.
  2. Each nested object becomes its own named interface, referenced by the parent, so the types read the way you would write them.
  3. Arrays are typed by their first element, and the element type of an object array gets a sensible singular name.
  4. Primitive types map directly: a JSON string becomes string, a number becomes number, a boolean becomes boolean.
  5. You can name the root interface; nested ones are named from their field keys.

Where json to typescript helps

Typing an API response

Paste a real response body and get the interface. Then widen any fields the API documents as optional or nullable.

Bootstrapping a data model

Generate the interfaces from sample data, then refine names and optionality by hand.

Before you use the result

Questions about JSON to TypeScript

Does it handle nested objects?

Yes. Each becomes its own named interface referenced by its parent, rather than an inline type.

Why aren't any fields optional?

A single sample cannot prove optionality. It types what the example contains; widen fields to optional or nullable yourself.

How are arrays typed?

By their first element. An empty array becomes unknown[], since there is nothing to infer.

Can I name the root type?

Yes. There is a field for the root name; nested interfaces are named from their keys.

Related tools

JSON to Go Struct

Generate Go structs from a JSON sample in your browser, complete with json struct tags.

JSON to JSON Schema

Generate a JSON Schema from a sample document in your browser, inferring types and required fields.