zod-json-parsing

zod-json-parsing is a cursor rule for Cursor from maccman/ai-monorepo-scaffold. It costs 856 tokens per session, scanned A, original, MIT.

A rule requiring Zod, a TypeScript library for checking data shapes, whenever JSON is read or parsed.

In plain words
What is it for?
Use it when reading API responses, request bodies, or other JSON data in TypeScript applications.
Why use it?
It prevents code from trusting unverified JSON and makes invalid API responses or request bodies fail in a controlled way.

Cursor rule for Cursor

Written for Cursor: installed under .cursor/.

Good fit Use it when reading API responses, request bodies, or other JSON data in TypeScript applications.

Compare 6 cursor rules from other repositories ↓
Install with agentmods
npx agentmods add rules/maccman/ai-monorepo-scaffold/zod-json-parsing
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Clone the repo
git clone --depth 1 https://github.com/maccman/ai-monorepo-scaffold

Made for: Cursor.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for zod-json-parsing

README.md
[![agentmods](https://agentmods.dev/badge/rules/maccman/ai-monorepo-scaffold/zod-json-parsing/github.svg)](https://agentmods.dev/rules/maccman/ai-monorepo-scaffold/zod-json-parsing)
Your own site
<a href="https://agentmods.dev/rules/maccman/ai-monorepo-scaffold/zod-json-parsing"><img src="https://agentmods.dev/badge/rules/maccman/ai-monorepo-scaffold/zod-json-parsing/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for zod-json-parsing

Your own site · 80×15
<a href="https://agentmods.dev/rules/maccman/ai-monorepo-scaffold/zod-json-parsing"><img src="https://agentmods.dev/badge/rules/maccman/ai-monorepo-scaffold/zod-json-parsing.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 856 This file is loaded in full into every session.
When invoked 856 The same file — it is already loaded in full.
Security scan A 1 finding. A grade says what 26 rules found in the file — not that it is safe.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00856 $0.00856
Opus 5 $0.00428 $0.00428
Sonnet 5 $0.00171 $0.00171
Haiku 4.5 $0.00086 $0.00086

Measured 11d ago against content hash 16aefc495cc6, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-11, from the pricing page.

Security

Grade A, and why

zod-json-parsing scanned grade A with 1 finding against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 11d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Makes network callslowCapability

Not a fault in itself. Listed so you know the mod talks to something, and to what.

const response = await fetch(externalApi)
.cursor/rules/zod-json-parsing.mdc · 163 lines

How it starts

The opening of the file, as written. The whole thing — 163 lines — stays where its author put it; the contents beside it link to each section on GitHub.

JSON Parsing - MANDATORY Zod Validation

NEVER USE TYPE ASSERTIONS FOR JSON

VIOLATION EXAMPLES (DO NOT DO THIS):

// ❌ WRONG: Type assertion
const result = (await response.json()) as SomeType

// ❌ WRONG: Unsafe parsing
const body = await request.json()
const { field } = body

// ❌ WRONG: Any type
const data: any = await response.json()

CORRECT APPROACH - ALWAYS USE ZOD:

// ✅ CORRECT: Zod schema validation
const resultSchema = z.object({
  success: z.boolean(),
  data: z.string(),
})

const result = resultSchema.parse(await response.json())

// ✅ CORRECT: Request body parsing
const requestSchema = z.object({
  retailerId: z.string().uuid(),
  force: z.boolean().optional(),
})

const body = requestSchema.parse(await request.json())

MANDATORY PATTERNS

1. Define Zod Schema First

// Always define the schema before parsing
const apiResponseSchema = z.object({
  message: z.string(),
  data: z.array(
    z.object({
      id: z.string(),
      name: z.string(),
    }),
  ),
})

type ApiResponse = z.infer<typeof apiResponseSchema>

2. Parse with Error Handling

// Handle Zod validation errors gracefully
try {
  const parsed = schema.parse(rawData)
  return parsed
} catch (error) {
  console.error('Validation failed:', error)
  throw new Error('Invalid data format')
}

3. API Endpoint Pattern

export const POST: APIRoute = async ({ request }) => {
  try {
    // Define schema for request body
    const requestSchema = z.object({
      field1: z.string(),
      field2: z.number().optional(),
    })

    // Parse with Zod (never type assertion)
    const body = requestSchema.parse(await request.json())

    // Use the validated data
    const result = await businessLogic(body)

    return new Response(JSON.stringify(result))
  } catch (error) {
    // Handle Zod validation errors
    return new Response('Invalid request', { status: 400 })
  }
}

4. External API Response Pattern

Read the full file on GitHub · 163 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 11d ago First seen · 163 lines · 856 tokens per session scan A 16aefc495cc6

Subscribe to this mod's changes

zod-json-parsing is a cursor rule published in the GitHub repository maccman/ai-monorepo-scaffold (304 stars, last pushed 10mo ago), licensed MIT. It adds 856 tokens to every session, about $0.0043 per session on Opus 5. A static security scan graded it A with 1 finding (makes network calls). No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.