递归密钥的JSON模式

发布于 2025-02-07 17:56:27 字数 608 浏览 0 评论 0原文

JSON数据作为给定,并具有多个实例中的学生的名称,例如100(只有3个给定)。因此,是否有一种方法可以为键和值提供#defs来简化模式?

{
  "student_id": {
    "Alice": 0,
    "Bob": 1,
    "Charlie": 2,
    "Derek": 3,
    "Emily": 4,
    "Florence": 5
  },
  "project": {
    "Alice": "Science",
    "Bob": "Math",
    "Charlie": "Science",
    "Derek": "Science",
    "Emily": "Math",
    "Florence": "Math"
  },
  "summer_camp": {
    "Alice": true,
    "Bob": false,
    "Charlie": true,
    "Derek": false,
    "Emily": true,
    "Florence": false
  },
  "Data":[
    "student_id",
    "project",
    "summer_camp"
   ]
}

json data as given and have the names of the students in multiple instance like 100 (only 3 given). So, is there a way to give a #defs for a key and value to simplify the schema?

{
  "student_id": {
    "Alice": 0,
    "Bob": 1,
    "Charlie": 2,
    "Derek": 3,
    "Emily": 4,
    "Florence": 5
  },
  "project": {
    "Alice": "Science",
    "Bob": "Math",
    "Charlie": "Science",
    "Derek": "Science",
    "Emily": "Math",
    "Florence": "Math"
  },
  "summer_camp": {
    "Alice": true,
    "Bob": false,
    "Charlie": true,
    "Derek": false,
    "Emily": true,
    "Florence": false
  },
  "Data":[
    "student_id",
    "project",
    "summer_camp"
   ]
}

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

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

发布评论

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

评论(1

予囚 2025-02-14 17:56:27

您可以在可重复使用的定义中指定属性名称:

{
  "$defs": {
    "property_names_students": {
      "propertyNames": {
        "enum": [
          "Alice",
          "Bob",
          ...
        ]
      ]
    }
  },
  "type": "object",
  "properties": {
    "student_id": {
      "$ref": "#/$defs/property_names_students",
      "additionalProperties": {
        "type": "integer"
      }
    },
    "project": {
      "$ref": "#/$defs/property_names_students",
      "additionalProperties": {
        "enum": ["Science", "Math", ... ]
      }
    },
    ...
  }
}

You can specify the property names in a reusable definition:

{
  "$defs": {
    "property_names_students": {
      "propertyNames": {
        "enum": [
          "Alice",
          "Bob",
          ...
        ]
      ]
    }
  },
  "type": "object",
  "properties": {
    "student_id": {
      "$ref": "#/$defs/property_names_students",
      "additionalProperties": {
        "type": "integer"
      }
    },
    "project": {
      "$ref": "#/$defs/property_names_students",
      "additionalProperties": {
        "enum": ["Science", "Math", ... ]
      }
    },
    ...
  }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文