JSON to TypeScript Types

Paste JSON, get TypeScript interfaces, type aliases, Zod schemas, or Valibot schemas. Updates as you type.

interface Root {
  id: number;
  user: RootUser;
  active: boolean;
  createdAt: string;
}

interface RootUser {
  name: string;
  email: string;
  tags: string[];
}

01 — Overview

How the JSON to TypeScript Types works

Convert any JSON sample into a TypeScript type definition or runtime schema. Toggle between interface, type alias, Zod, and Valibot output. Configure root name, optional fields, readonly modifiers, and how to handle nulls. Powered by quicktype.

02 — Use cases

When to use the JSON to TypeScript Types

  1. 01

    Generate types for a third-party API you only have a sample response from

  2. 02

    Bootstrap a Zod schema from a JSON fixture

  3. 03

    Convert an inherited JSON blob into proper TypeScript before refactoring

  4. 04

    Add runtime validation to a route that previously trusted unknown input

03 — Examples

JSON to TypeScript Types examples

{ "id": 1, "name": "Alex", "active": true }

ex 01

interface Root { id: number; name: string; active: boolean; }

Basic interface inferred from a single sample.

{ "items": [{ "id": "a" }, { "id": "b", "label": "B" }] }

ex 02

interface Root { items: Item[]; } interface Item { id: string; label?: string; }

Array items are merged and fields present in only some objects become optional.

{ "id": 1, "name": "Alex" } // Zod output

ex 03

z.object({ id: z.number(), name: z.string() })

Same shape as a Zod schema for runtime validation.

04 — FAQ

JSON → Types — frequently asked questions

How does the tool decide whether a field is optional?

For an array of objects, any field that's missing from at least one object becomes optional. For a single object, every field is required by default. You can toggle the 'mark optional' option to soften this.

What's the difference between an interface and a type alias?

For object shapes, they're nearly interchangeable. Interfaces can be augmented via declaration merging; type aliases support unions and primitives. The tool picks interface by default for object-shaped JSON.

When should I use Zod or Valibot instead of TypeScript types?

Use plain TS types when the data is already trusted (e.g. you control the producer). Use Zod or Valibot at the trust boundary — incoming HTTP requests, external API responses, env vars — where you want runtime validation to back the static type.

Why is a number sometimes typed as 'number' and sometimes as a literal?

If every sample shows the same literal value, the tool can narrow to that literal — useful for status fields like 'success' or 'error'. By default it widens to the broader primitive; you can override with the 'narrow literals' option.

How do nulls become 'unknown'?

When a field is null in the sample, the tool can't tell what its non-null type is. The default is to emit T | null where T is best-guessed, but you can switch to unknown to be more strict.

Does it support deeply nested objects?

Yes. Each nested object becomes its own type, named after the field. You can rename types in the output panel.

05 — Reference

Specs and further reading

The primary sources this tool follows. Where behaviour is defined by a specification, we link the specification rather than a summary of it.

  • RFC 8259: The JSON Data Interchange Format

    IETF — The normative definition of JSON, including its value types and encoding rules.

  • TypeScript everyday types

    Microsoft — Reference for the interface and type-alias forms this tool emits.

  • Zod

    Zod — Documentation for the runtime schema output option, including inference to static types.

  • quicktype

    quicktype — The type-inference engine used to derive types from a JSON sample.

07 — More

Tools that pair with JSON → Types

Last updated .