Gemini Structured Output With Zod in Next.js
Describe the JSON once in Zod, send z.toJSONSchema() to Gemini as responseJsonSchema, then validate the reply with safeParse and retry once with the errors.
Sample article. This note demonstrates the blog layout. It is not a published achievement.
This sample note shows a second article card, a category, and related posts. I wrote it as layout practice. It does not describe a completed website for a client.
An HTML page starts with a document type, a head, and a body. The head holds the title. The body holds the words and pictures people actually see.
<main>
<h1>Mahir Faysal</h1>
<p>Student and aspiring developer.</p>
</main>CSS is how I change spacing, color, and layout. I am still learning how to keep a page comfortable on a phone and on a large screen.
// note
The banner at the top is the important line. This article is sample layout practice. It shows how a post looks on the site. It is not a tutorial I am publishing as a finished explanation, and it is kept out of the sitemap.
If a sentence is wrong, say so from the contact page and name this title. Drafts never appear here. Related notes, when they exist, are other published posts, and the same sample rule applies to each of them.
Describe the JSON once in Zod, send z.toJSONSchema() to Gemini as responseJsonSchema, then validate the reply with safeParse and retry once with the errors.
Step by step: a Gemini key from Google AI Studio in .env.local, a server-only helper, a Next.js route handler, Vercel environment variables and a leak test.
A small offline habit tracker in plain HTML and JavaScript: habits saved as JSON in localStorage, streaks from local dates, a 7-day row and a JSON backup.