From an API payload to a Zod validation schema
- Paste a JSON object, array, or primitive value into the input.
- Review the generated Zod schema. Add application-specific constraints such as email validation or minimum string lengths.
- Copy the output into your project. Switch format to compare compile-time types and runtime validation.
Validate a response at runtime
const result = rootSchema.safeParse(apiResponse);
if (result.success) {
console.log(result.data);
} else {
console.log(result.error.issues);
}Zod checks values when your application runs. Inferred schemas describe the examples you provide; they cannot discover business rules or field types missing from the sample.
How arrays and optional fields are inferred
Every array element is inspected. For [{"id":1},{"id":2,"name":"Ada"}], name is optional. Mixed value types become unions. An empty array uses an unknown element type until an example supplies more information.
Continue the workflow
Use API response fixtures as examples, then exercise your schema with the mock data generator. Read the JSON-to-Zod validation guide for a complete example.