JSON to Types

JSON to a TypeScript interface

The basic case: a flat object of scalars becomes one interface with the same keys.

Input

{
  "id": 42,
  "name": "Ada Lovelace",
  "email": "ada@example.com",
  "active": true
}

A single object shape.

1 interface · 4 fields · 1 levels deep

Where this sample is ambiguous

  • Note

    Whole numbers are still `number`

    Every numeric value in the sample was a whole number, but JSON has a single number type and cannot express the difference. The output uses `number`.

    Fix: If a field is genuinely an integer, tighten it by hand: `z.number().int()`.

TypeScript

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

Zod

import { z } from 'zod';

export const RootSchema = z.object({
  id: z.number(),
  name: z.string(),
  email: z.string(),
  active: z.boolean(),
});

Convert your own JSON

Paste a sample on the home page, or call the API or MCP server. This page is also available as markdown.

Related examples