JSON to Types

JSON to a Zod schema

The same inference, emitted as a runtime validator. Optional and nullable are kept distinct.

Input

{
  "userId": 7,
  "nickname": null,
  "tags": ["admin", "beta"]
}

A single object shape.

1 interface · 3 fields · 2 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 {
  userId: number;
  nickname: null;
  tags: string[];
}

Zod

import { z } from 'zod';

export const RootSchema = z.object({
  userId: z.number(),
  nickname: z.null(),
  tags: z.array(z.string()),
});

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