Skip to content
Type helper

JSON to TypeScript types

Create a TypeScript type (type Root = { ... };) from a JSON sample. Paste an API response or a config file and you have a starting point for typing it. When array elements have different shapes they are merged into one type, and a key present in only some elements becomes optional, like email?: string. An empty array becomes unknown[] and a value that includes null becomes a union such as string | null. Numbers, whole or not, are number and date strings are string, and nested objects are output inline without separate names. Because it infers from a single sample, adjust whether keys are required, enums and the extraction of shared types to match your spec. Everything runs in your browser and your JSON is not sent anywhere.

Other languages: Go, Python, Rust, Kotlin, C#

Turn the JSON above into a type for another language: Go structs (with json tags), Python TypedDict (3.11+), Rust serde structs, Kotlin data classes (kotlinx.serialization) and C# classes (System.Text.Json). Nested objects become named types, missing keys become optional, and nothing is sent anywhere.

Guide

How to use & features

  • Paste JSON into the input and click “Convert to TypeScript.”
  • Objects are formatted into a structured block with typed properties.
  • Arrays are analyzed to determine element types; mixed content becomes a union.
  • Use the copy or clear buttons to reuse the output or start over.
Samples

Sample input & output

Generate TypeScript types

Input
{"title":"Draft","tags":["dev","web"],"stats":{"views":1200}}
Output
type Root = {
    title: string;
    tags: string[];
    stats: {
        views: number;
    };
};
FAQ

FAQ

  • What type is output?

    A type alias of the form `type Root = { ... };`. Nested objects are output inline without separate names. Rename it or turn it into an `interface` by hand if you wish.
  • What happens when array elements have different shapes?

    They are merged into one type. A key that only some elements have becomes optional, like `email?: string`. A union such as `string | number` appears only when the kinds of value differ.
  • What about empty arrays and `null`?

    An empty array becomes `unknown[]` because the element type is unknown (not `any[]`). A value that includes `null` becomes a union such as `string | null`.
  • Are integers, decimals and dates distinguished?

    No. All numbers are `number` and date strings are `string`. You do not get `Date` or `bigint`.
  • What about keys that are not identifiers, such as `my-key`?

    They are quoted in the output, as in `"my-key": string;`.
  • Is my JSON sent anywhere?

    No. Conversion happens entirely in your browser.
Use cases

Common use cases

  • Quickly typing an API response

    Paste a real response to get a starting point for the type you attach to a `fetch` result.
  • Typing config files and JSON data

    Write out the shape of `config.json` or any JSON your app loads as a type.
  • Keeping mock data aligned with real data

    Make a type from test JSON so that mock data and real data are easier to keep in the same shape.
  • Making a draft type definition

    Instead of writing from scratch, build the skeleton from a sample and fix only names and extraction of shared types by hand.
Notes

Notes & limitations

  • It infers from a single sample

    Types come only from the values in your JSON. Specification knowledge, such as "this is really an enum" or "this key is required", is not included. Always review the result.
  • Nested objects are not given names

    Output stays inline, so a shape that repeats is not merged into a shared type. Extract it yourself, for example as `type User = ...`.
  • Dictionary-like JSON does not become `Record`

    An object whose keys vary, such as IDs, becomes a type of only the keys it saw. Rewrite to `Record<string, T>` by hand where that fits.
  • Large integers are rounded

    Integers that JavaScript numbers cannot represent exactly are rounded when the JSON is read. Consider receiving values such as IDs as strings.
About

About this tool

JSON to TypeScript Type & Interface Generator

Automatically generate TypeScript interface and type definitions with just one click by parsing sample JSON responses or dummy data payloads.
This drastically cuts down the hours spent manually writing type definition files required for strict type enforcement in modern frontend development frameworks (like Next.js, React, or Vue). It seamlessly parses deeply nested objects and arrays, integrating smoothly into your secure, local workflow.

Common use cases

  • Type API responses: Paste a real response body and create a starting point for frontend types.
  • Document payload shape: Turn sample JSON into readable TypeScript definitions for teammates.
  • Speed up prototyping: Generate temporary interfaces while exploring unfamiliar APIs.

Review before production

Generated types are inferred from the sample you provide. If an API can return optional fields, nullable values, mixed arrays, or error responses, review the generated result and adjust it to match the real contract.

Articles for this tool

Recent Articles