如何在JSON模式中为一个字段定义不同的类型?

发布于 2025-01-25 01:02:14 字数 53 浏览 3 评论 0原文

例如,需要验证字段等级 - 而不是空白字符串(可以转换为整数)或1000和1000之间的整数

For example, need to validate field GRADE - not blank string (which can be converted to integer) or integer between 1 and 1000

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

路还长,别太狂 2025-02-01 01:02:14

最基本的定义是:

      "GRADE": {
        "type": ["string", "integer"],
        "pattern": "^[0-9]+$"
      }

请查看模式关键字,如下所述: https://json-schema.org/understanding-json-schema/reference/reference/string.html#id6

您可以定义一个确切的正则表达式年级领域的要求。

The most basic definition would be:

      "GRADE": {
        "type": ["string", "integer"],
        "pattern": "^[0-9]+
quot;
      }

Take a look at the pattern keyword as described in detail here: https://json-schema.org/understanding-json-schema/reference/string.html#id6

You can define a regular expression that meets your exact requirements for the GRADE field.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文