a11y.skipToMainContent
1

JSON 呼叫 Zod Schema

粘贴 JSON 并获得一个可随时使用的 <code>z.object ({.}) </code> Zod schema外加推断出的类型Script.

More options
Was this tool helpful?
Send output to:
Advertisement

How to use JSON to Zod Schema

  1. 粘贴 JSON 对象 .
  2. 选择一个 schema 变量名称 .
  3. 选中“ 导出类型” 也可以获取<code>z.infer<typeof chema></code>.
  4. 粘贴结果到您的 TypeScript 项目中 .

{姓名}是什么来着?

Zod是TypeScript生态系统中最受欢迎的运行时间验证库. 这个工具从 JSON 样本中生成匹配的 schema, 这样您就可以验证 API 响应, 形成输入, 或 env vars 不写入锅炉板 。 看起来像电子邮件、 URL、 UUID 或 ISO 日期时间自动获得匹配的 Zod 方法的字符串。

Advertisement

FAQ

它检测到哪种格式?
电子邮件、 url、 uuid 和日期时字符串获得匹配的. email () /. url () /. uuid () /. datetime () 方法 .
需要Zod安装吗?
是 — 生成的代码使用标准的<code>zod</code>包. 用 <code>npm i zod</code>安装.

Related tools

Author

MW
Marcus Webb"The DevTool Craftsman"

Full-Stack Developer & Tools Architect

Marcus has been writing code since the dial-up era. He has contributed to open-source developer tools, built CI/CD pipelines for startups, and debugged production incidents at 3 AM more times than he would like to admit. His philosophy is that the best developer tool is the one that gets out of your way, and he writes about practical tooling that helps teams ship faster with fewer headaches.

← Back to Developer Tools · All tags

Last updated:

Advertisement