Dad’s Data formats tools

JSON → Zod Schema

Generate Zod validation schemas from JSON — nested objects, unions, and optional fields. 100% local.

JSON Input
Root schema name
Zod Schema Output
Paste JSON to generate a Zod schema.

Generated Schema Structure

The Zod schema generator produces a runnable z.object(...) schema that validates the same shape as your JSON sample. Each nested object becomes a named z.object variable. The generated code can be dropped directly into a TypeScript file and used with parse() or safeParse().

Input
{
  "user": {
    "id": 1,
    "name": "Alice",
    "email": "[email protected]",
    "role": "admin",
    "tags": ["typescript", "zod"],
    "address": {
      "city": "London",
      "country": "UK"
    },
    "metadata": null
  },
  "total": 42,
  "active": true
}
Output
import { z } from 'zod';

export const AddressSchema = z.object({
  city: z.string(),
  country: z.string(),
});

export const UserSchema = z.object({
  id: z.number(),
  name: z.string(),
  email: z.string(),
  role: z.string(),
  tags: z.array(z.string()),
  address: AddressSchema,
  metadata: z.null(),
});

export const RootSchema = z.object({
  user: UserSchema,
  total: z.number(),
  active: z.boolean(),
});

Zod Type Mapping

JSON valueZod schemaUsage
Stringz.string()Any string
Numberz.number()Integer or float
Booleanz.boolean()true / false
nullz.null()Null only — usually change to z.nullable(z.string()) etc.
Array of stringsz.array(z.string())Typed array
Mixed arrayz.array(z.union([...]))Union of element types
Objectz.object({...})Nested schema
Empty arrayz.array(z.unknown())Inferred as unknown

Customizing Generated Schemas

The generated schema is a starting point. Common manual adjustments after generation:

Change z.null() to z.nullable(z.string()) for fields that can be string or null. Add .optional() for fields that might be absent: z.string().optional(). Add .min(1) for required non-empty strings: z.string().min(1). Add .email() for email fields: z.email(). Add .url() for URL fields: z.url(). Add .int() for integer-only numbers: z.number().int().

Try It

Interactive — edit the input to see the output update
Try it
Result

Frequently Asked Questions

Your files stay on your computer. Dad promised.

Data formats tools

Search the Data formats tools