Zod Examples You Can Edit and Run
5 small Zod examples written by AgentGid from the official docs, one feature each. Every one runs in your browser: change the code and see the result at once, or describe a change and let AI rewrite it. The screenshots are taken from the same code by our server, which also checks that each example starts without errors.
Zod: usage and stats 1,553 AI-built projects use it
Handling errors with ZodError in ZodChange the invalid object so only one field is wrong and watch the issue list shrink.
String formats in Zod: email, UUID, phone, datetimeEach line prints the format name, the value and whether it passed.
String validation in ZodTry inputs like "ab" or "has space" to see which rule reports an issue.
Type coercion in ZodThe boolean lines print what z.coerce.boolean() returns for each value, including the string "false".
Literal values in ZodAdd "yellow" to the literal array and run again to see it pass.
Try them all in one place
import * as z from "zod";
const Player = z.object({
username: z.string(),
xp: z.number(),
});
// valid input: parse returns the value
const ok = Player.parse({ username: "billie", xp: 100 });
console.log("parsed:", JSON.stringify(ok));
// invalid input: parse throws
try {
Player.parse({ username: 42, xp: "100" });
console.log("no error thrown");
} catch (err) {
if (err instanceof z.ZodError) {
console.log("ZodError with", err.issues.length, "issues:");
for (const issue of err.issues) {
console.log(" path:", issue.path.join("."));
console.log(" code:", issue.code);
console.log(" message:", issue.message);
}
} else {
console.log("other error:", String(err));
}
}
Change the invalid object so only one field is wrong and watch the issue list shrink. Code written by AgentGid [1]. How it works, with a screenshot →
Change the invalid object so only one field is wrong and watch the issue list shrink. Code written by AgentGid [1]. How it works, with a screenshot →Each line prints the format name, the value and whether it passed. Code written by AgentGid [2]. How it works, with a screenshot →Try inputs like "ab" or "has space" to see which rule reports an issue. Code written by AgentGid [2]. How it works, with a screenshot →The boolean lines print what z.coerce.boolean() returns for each value, including the string "false". Code written by AgentGid [3]. How it works, with a screenshot →Add "yellow" to the literal array and run again to see it pass. Code written by AgentGid [4]. How it works, with a screenshot →Checked Oct 12, 2026: each example starts without errors in Chromium with zod 4.6.6. Needs WebGL.
Sources
Explanations written by AgentGid from the official docs; the numbers in brackets point here. The code marked "written by AgentGid" is ours and free to copy.