Zod Showcase
Exercise 1 of 6

User Registration

A SvelteKit server endpoint validates incoming JSON with Zod. The request body below starts empty — every field will fail. Your task: edit the JSON so all four fields satisfy the schema on the left and the endpoint returns 200 OK. Complete that and the next exercise unlocks.

Endpoint schema POST /api/playground/user
import { z } from 'zod';

const UserSchema = z.object({
  username: z.string().min(3, 'Username must be at least 3 characters'),
  email: z.email('Invalid email address'),
  password: z.string().min(8, 'Password must be at least 8 characters'),
  age: z.number().int().min(18, 'Must be 18 or older'),
});
Request body (JSON)
Hints
  • username must be at least 3 characters
  • email must be a valid email address
  • password must be at least 8 characters
  • age must be a number (not a string) and at least 18
  • All four fields are required — removing one will fail