{ JSON to TypeScript }

// generate TypeScript interfaces from JSON instantly

Convert JSON objects to TypeScript interfaces, types, or Zod schemas instantly. Handles nested objects, arrays, optional fields, and union types — browser-based, free, no signup.

// OPTIONS
OUTPUT
ROOT NAME
JSON INPUT
TS TYPESCRIPT

TypeScript output appears here

Paste JSON and click Generate

HOW TO USE

  1. 01
    Paste JSON

    Paste any JSON — a single object, an array, or a deeply nested structure. The generator analyses the shape of your data immediately.

  2. 02
    Choose output format

    Pick between TypeScript interface, type alias, or a Zod validation schema. Set the root type name and toggle optional, readonly, and export modifiers.

  3. 03
    Copy or download

    Click "▶ Generate" or type and it generates live. Copy the result or download as a .ts file ready to import into your project.

FEATURES

interface / type Zod Schemas Union Types Optional Fields Nested Objects Array Types Readonly Support Type Tree View

USE CASES

  • 🔧 Type API responses from REST or GraphQL endpoints
  • 🔧 Generate Zod schemas for runtime validation
  • 🔧 Scaffold types for database model objects
  • 🔧 Convert JSON config files to typed interfaces

WHAT IS THIS?

The JSON to TypeScript generator analyses the structure of any JSON value and produces accurate TypeScript type definitions. It detects optional fields (keys missing from some array items), union types (arrays with mixed-type elements), nullable fields (null values), and nested object structures — generating a clean hierarchy of named types.

RELATED TOOLS

FREQUENTLY ASKED QUESTIONS

How are optional fields detected?

When the input is an array of objects, the generator computes the union of all keys across every object. A key that appears in some objects but not all is marked optional with ?. For example, if half the objects have a role field and half don't, the generated type will have role?: string.

How are null values handled?

When "null union types" is enabled, a field whose value is null generates a union with null — for example age: number | null. When disabled, null fields are typed as unknown. The correct choice depends on whether your API guarantees the field is never null after data is loaded.

What is the Zod output format?

Zod is a TypeScript-first schema validation library. The Zod output generates z.object(), z.string(), z.number() etc. schemas that you can use directly with z.parse() or z.safeParse() for runtime validation of API responses. The generated schemas are inferred-type compatible — you can use z.infer<typeof Schema> to get the TypeScript type automatically.

How are arrays typed?

If all elements in an array are the same type, the output is string[] or number[]. If elements are all objects, a named sub-interface is generated for the item shape. If elements have mixed primitive types, a union type is used — (string | number)[]. Empty arrays produce unknown[].

What does "Export keyword" do?

When enabled, every generated interface and type alias includes the export keyword — export interface Root { ... }. This makes the types importable from other TypeScript files. Disable it if you're pasting the types into an existing file where you want to add export declarations manually.

Can I use this with arrays at the root level?

Yes. If you paste a JSON array as the root, the generator produces a type for the array items and wraps it in the root type — for example type Root = RootItem[]. The item shape is analysed across all elements in the array, including optional field detection.

JSON to TypeScript Generator — Instant Type Safety from API Responses

When consuming a REST API in TypeScript, the first step is almost always the same: paste the response JSON into an editor and manually write an interface for it. For small responses this takes minutes; for deeply nested API payloads with dozens of fields it takes much longer and is error-prone. This generator automates the entire process.

interface vs type Alias

TypeScript offers two ways to define object shapes: interface and type aliases. Interfaces can be extended and merged — useful for building hierarchies and for declaration merging with third-party types. Type aliases are more flexible — they can represent unions, intersections, and mapped types. For plain object types from JSON, both are functionally equivalent. Use interfaces for data models you plan to extend; use type aliases for inferred shapes from parsed JSON.

Generating Zod Schemas

Zod schemas go a step further than TypeScript interfaces — they validate data at runtime, not just at compile time. When you call z.safeParse(apiResponse), Zod verifies that the actual data matches the expected shape, throwing descriptive errors for mismatches. This is essential for any TypeScript project that consumes external APIs, where the actual runtime data may not match what the docs describe. The Zod output from this generator is immediately usable for runtime validation.

Handling Heterogeneous Arrays

Real API responses often contain arrays where not every object has exactly the same shape. This generator analyses all items in an array simultaneously — computing the union of all keys and marking fields that are absent from any item as optional. The result is a type that accurately represents the full range of shapes that can appear in the array, without false positives or missed fields.