JSON to TypeScript Interface Generator

Paste JSON and instantly generate TypeScript interfaces. Recursively handles nested objects, arrays, union types, and nullable fields. 100% client side.

About JSON to TypeScript Conversion

This tool analyzes the structure of your JSON data and generates corresponding TypeScript interfaces. It recursively processes nested objects and detects array element types to produce accurate, ready-to-use type definitions.

Features

  • Recursively generates interfaces for nested objects
  • Detects array element types (primitives, objects, mixed)
  • Handles null values as any (nullable)
  • Converts JSON keys to valid TypeScript property names
  • Custom root interface naming

How It Works

  • Primitive values map to string, number, or boolean
  • Nested objects generate separate named interfaces
  • Arrays of objects generate item interfaces (e.g., ITagsItem)
  • Null values become any since the type cannot be inferred

Related Tools

From JSON Sample to TypeScript Interface

Reverse-engineering a TypeScript type from a JSON example is one of the most common one-off tasks for a frontend or full-stack engineer. The API doesn't have an OpenAPI spec, the team's docs are out of date, but you have a sample response — the fastest path to compiler-checked code is generating a starter interface from that sample, then refining.

What automatic generation gets right

  • Object shapes — every key becomes a property.
  • Primitive types (string, number, boolean, null).
  • Arrays of homogeneous primitives.
  • Nested objects (recursively).
  • Optional vs required (best-effort, based on which keys appear in all samples).

What it can't infer (and what you must add)

  • Union types. A field that's sometimes string, sometimes null, sometimes missing — generators guess string | null | undefined but can't know if other variants exist.
  • String literal unions. status: "active" in your sample looks like string, but the API might emit "active" | "pending" | "cancelled". You have to know the domain.
  • Enums. Generators don't promote literal unions to enums — you decide.
  • Nullable arrays. Empty arrays [] get any[] or never[] depending on the tool. Always specify the element type manually.
  • Date strings. "2026-05-03T12:00:00Z" looks like string. If you parse it to a Date later, type the field as Date after parsing.
  • Numeric IDs that should be branded. A type alias like type UserId = number & { __brand: 'UserId' } prevents passing a UserId where a PostId is expected.

Workflow recommendations

  1. Capture multiple sample responses — one with every optional field populated, one minimal.
  2. Run the generator on each. Diff the results.
  3. Manually merge the differences into a final interface, marking optional fields with ?.
  4. Tighten string fields to literal unions where you know the domain.
  5. Run your own code against the type and let the compiler surface mismatches.
  6. If the API is documented in OpenAPI/JSON Schema, prefer generating from that — it's authoritative.

When to use Zod or io-ts instead

For external APIs you don't control, runtime validation matters as much as compile-time types. Schema libraries like Zod, io-ts, and ArkType produce both at once: you write a schema, you get a TypeScript type AND a runtime validator. The validator catches API drift you wouldn't notice at compile time.

This generator is a starting point — not the finish line. It runs entirely in your browser, so confidential payloads stay local.

Frequently Asked Questions

How do I handle fields that are sometimes null?

After generation, change the field type to "T | null" (or add ? for optional). The generator may default to one or the other based on your samples.

Should I use type or interface?

For object shapes that might be extended, interface. For unions, intersections, or one-off shapes, type. Most modern style guides use type by default.

What if my JSON has duplicate keys with different shapes?

Standard JSON forbids duplicate keys. If your input has them, the parser keeps only the last value — review your source.

Can I generate types from a remote API?

Save a sample response to a file or paste it here. For canonical types, use the API's OpenAPI/Swagger spec with openapi-typescript instead.