惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

爱范儿
爱范儿
博客园_首页
U
Unit 42
Apple Machine Learning Research
Apple Machine Learning Research
云风的 BLOG
云风的 BLOG
MongoDB | Blog
MongoDB | Blog
美团技术团队
H
Help Net Security
G
Google Developers Blog
B
Blog RSS Feed
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
aimingoo的专栏
aimingoo的专栏
Google DeepMind News
Google DeepMind News
J
Java Code Geeks
M
MIT News - Artificial intelligence
腾讯CDC
IT之家
IT之家
Vercel News
Vercel News
C
Check Point Blog
博客园 - 三生石上(FineUI控件)
Last Week in AI
Last Week in AI
I
InfoQ
博客园 - 司徒正美
A
About on SuperTechFans

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
I ran one API response through two JSON-to-Zod converters...
Jop · 2026-06-24 · via DEV Community

Jop

You have an API response. You want a Zod schema. So you paste the JSON into a JSON-to-Zod converter, copy the output, and ship it.

Here's the trap: a lot of those converters infer basic types only. Your email, your uuid, your url, your ISO timestamp — they all come out as z.string(). The schema compiles, the types look right, and your validator quietly accepts "not-an-email", "ftp://nope", and "2026-99-99" forever.

I wanted to see exactly how much gets lost, so I ran the same payload through two tools and diffed the output. Everything below is real, copy-pasteable output — nothing edited.

The input

A pretty ordinary user object:

{
  "id": "3f2a9c1e-5b7d-4e8a-9f1c-2d3e4f5a6b7c",
  "email": "ada@example.com",
  "website": "https://ada.dev",
  "age": 34,
  "rating": 4.7,
  "created_at": "2026-03-04T10:15:30Z",
  "is_active": true,
  "address": { "city": "Lyon", "zip": "69001" },
  "tags": ["early-adopter", "beta"]
}

Tool 1 — json-to-zod (npm)

const user = z.object({
  id: z.string(),
  email: z.string(),
  website: z.string(),
  age: z.number(),
  rating: z.number(),
  created_at: z.string(),
  is_active: z.boolean(),
  address: z.object({ city: z.string(), zip: z.string() }),
  tags: z.array(z.string()),
});

Structurally correct. But every meaningful field is a bare z.string() / z.number(). This schema will happily validate email: "lol" and created_at: "yesterday".

Tool 2 — TypeMorph

import { z } from "zod";

export const userAddressSchema = z.object({
  city: z.string(),
  zip: z.string().regex(/^[A-Z0-9][A-Z0-9\s\-]{1,8}[A-Z0-9]$/i),
});
export type UserAddress = z.infer<typeof userAddressSchema>;

export const userSchema = z.object({
  id: z.uuid(),
  email: z.email(),
  website: z.url(),
  age: z.number().int().min(0).max(150),
  rating: z.number().min(0).max(5),
  created_at: z.iso.datetime(),
  is_active: z.boolean(),
  address: userAddressSchema,
  tags: z.array(z.string()),
});
export type User = z.infer<typeof userSchema>;

The honest diff

Field Value json-to-zod TypeMorph
id a UUID z.string() z.uuid()
email an email z.string() z.email()
website a URL z.string() z.url()
created_at ISO datetime z.string() z.iso.datetime()
age 34 z.number() z.number().int()…

Two things worth being honest about:

  1. The format detection is real and value-derived. z.uuid(), z.email(), z.url(), z.iso.datetime() come from looking at the actual values — they're facts, not guesses.
  2. The numeric ranges and the zip regex are name-based guesses. age.min(0).max(150), rating.min(0).max(5) are inferred from field names, not values, so they can be wrong (a rating could be 0–10). TypeMorph lets you turn that "smart" layer off and keep only the facts. I'd rather it be upfront about which is which than pretend a guess is a fact.

Why this matters

A Zod schema's whole job is to reject bad data. z.string() where you meant z.email() is a validator that passes the exact inputs you wrote it to catch. You get the feeling of validation with none of the coverage — which is worse than no schema, because you stop checking.

When json-to-zod is still fine

It's a tiny, zero-dependency function you can call inside your own code. If you just want a rough scaffold and you'll add .email() / .uuid() / enums by hand, it does the job. It's also basically unmaintained at this point (last publish was years ago), so don't expect Zod v4 output or fixes.

Try the comparison yourself

npx typemorph-cli zod your-response.json --root User


I'm building TypeMorph in public — a JSON/OpenAPI → Zod/TypeScript/Go/Prisma converter that tries to detect what your data actually is instead of dumping everything to z.string(). Feedback (and "your inference got this wrong") very welcome.