TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Ask HN: JSON API object type definitions and validation in 2023?

2 点作者 selbyk大约 2 年前
Hey HN,<p>We&#x27;re designing a new system and have been kicking the can about JSON object definitions and validation. Soon we need to settle on a system to validate API request bodies and provide helpful error messages. We would also like to generate Typescript types.<p>In the past, I&#x27;ve used JSON Schema ( https:&#x2F;&#x2F;json-schema.org&#x2F; ) to define definitions and ajv ( https:&#x2F;&#x2F;ajv.js.org&#x2F; ) to validate, but it&#x27;s a bit verbose and ajv validation errors are more cryptic than I&#x27;d like to deal with.<p>TypeSchema looks interesting. It seems solid (and perhaps stable?), but development hasn&#x27;t been active for 2 years. It also looks like we&#x27;d still need to generate JSON Schema and choose a validation library<p>Anyway, I&#x27;m very curious how others are approaching this problem. How do you organize and generate validations for your type definitions? What libraries do you use to validate and provide human readable error messages?<p>Thank you!

1 comment

satya71大约 2 年前
There&#x27;s a new spec, JSON Type Definition [1], but I don&#x27;t have any experience using it.<p>[1] <a href="https:&#x2F;&#x2F;jsontypedef.com&#x2F;" rel="nofollow">https:&#x2F;&#x2F;jsontypedef.com&#x2F;</a>