You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

请求协助创建指定JSON数据集的Schema(附草稿)

JSON Schema Improvements for Your Healthcare Dataset

Hey there! Let's walk through refining your JSON Schema to match your sample data and make it more robust. I've identified a few key issues in your draft and adjusted things to align with best practices.

Issues in the Original Schema

  • Incorrect type for AppointmentID: Your sample data has AppointmentID as a string ("A1234"), but your schema defines it as a boolean—that's a critical mismatch.
  • Invalid array reference: The Result array uses $ref directly, which isn't the right way to specify array items. You need to use the items keyword to link to the ResultType definition.
  • Missing required fields: None of your objects specify which fields are mandatory. Adding required arrays ensures that essential data (like ResourceName, Sequence, and all Data fields) can't be omitted.
  • Unrestricted ResourceName: Since ResourceName only ever takes one of three values, adding an enum will enforce valid values and prevent typos.

Revised JSON Schema

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "definitions": {
    "ResultType": {
      "type": "object",
      "required": ["ResourceName", "Sequence", "Data"],
      "properties": {
        "ResourceName": {
          "type": "string",
          "enum": ["Appointment", "EpisodeofCare", "Encounter"]
        },
        "Sequence": { "type": "string" },
        "Data": {
          "type": "object",
          "oneOf": [
            { "$ref": "#/definitions/Appointment" },
            { "$ref": "#/definitions/EpisodeofCare" },
            { "$ref": "#/definitions/Encounter" }
          ]
        }
      }
    },
    "Appointment": {
      "type": "object",
      "required": ["AppointmentID", "PatientName", "ClinicName"],
      "properties": {
        "AppointmentID": { "type": "string" },
        "PatientName": { "type": "string" },
        "ClinicName": { "type": "string" }
      }
    },
    "EpisodeofCare": {
      "type": "object",
      "required": ["EpisodeID", "LocationId", "AppointmentId", "TransactionStatus", "OPNumber"],
      "properties": {
        "EpisodeID": { "type": "string" },
        "LocationId": { "type": "string" },
        "AppointmentId": { "type": "string" },
        "TransactionStatus": { "type": "string" },
        "OPNumber": { "type": "string" }
      }
    },
    "Encounter": {
      "type": "object",
      "required": ["EncounterID", "PatientID"],
      "properties": {
        "EncounterID": { "type": "string" },
        "PatientID": { "type": "string" }
      }
    }
  },
  "type": "object",
  "required": ["Result"],
  "properties": {
    "Result": {
      "type": "array",
      "items": { "$ref": "#/definitions/ResultType" }
    }
  }
}

Key Improvements Explained

  1. Fixed AppointmentID type: Changed from boolean to string to match your sample data exactly.
  2. Proper array structure: Used the items keyword under the Result array to reference ResultType—this is the standard way to define schema for array elements.
  3. Added mandatory field checks: Every object now lists its required fields, so validation will fail if critical data points are missing.
  4. enum restriction for ResourceName: Locks values to the three valid resource types, stopping typos or invalid entries from slipping through.
  5. Switched anyOf to oneOf: Ensures that Data matches exactly one of the three resource schemas (instead of allowing partial overlaps), which better reflects your dataset's structure.

内容的提问来源于stack exchange,提问作者Ramesh

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.14 07:25:59