Zod schema from a JSON example

Prompt

Generate a Zod (v4) schema for this JSON example. Infer string formats (email, url, datetime) where obvious, mark fields that could be missing as optional, and export the inferred TypeScript type.

{json_example}

Sample output

Example run: json_example = {"id":"usr_8f2k","email":"ada@example.com","website":"https://ada.dev","created_at":"2026-10-01T09:30:00Z","tags":["admin","beta"],"bio":null}

import { z } from 'zod';

export const userSchema = z.object({
  id: z.string(),
  email: z.email(),
  website: z.url().optional(),
  created_at: z.iso.datetime(),
  tags: z.array(z.string()).default([]),
  bio: z.string().nullable().optional(),
});

export type User = z.infer<typeof userSchema>;

Notes: website and bio are likely missing for new users, so both are optional; bio is null in the sample, so it is also nullable.