请求协助创建指定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 hasAppointmentIDas a string ("A1234"), but your schema defines it as aboolean—that's a critical mismatch. - Invalid array reference: The
Resultarray uses$refdirectly, which isn't the right way to specify array items. You need to use theitemskeyword to link to theResultTypedefinition. - Missing required fields: None of your objects specify which fields are mandatory. Adding
requiredarrays ensures that essential data (likeResourceName,Sequence, and allDatafields) can't be omitted. - Unrestricted
ResourceName: SinceResourceNameonly ever takes one of three values, adding anenumwill 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
- Fixed
AppointmentIDtype: Changed frombooleantostringto match your sample data exactly. - Proper array structure: Used the
itemskeyword under theResultarray to referenceResultType—this is the standard way to define schema for array elements. - Added mandatory field checks: Every object now lists its required fields, so validation will fail if critical data points are missing.
enumrestriction forResourceName: Locks values to the three valid resource types, stopping typos or invalid entries from slipping through.- Switched
anyOftooneOf: Ensures thatDatamatches exactly one of the three resource schemas (instead of allowing partial overlaps), which better reflects your dataset's structure.
内容的提问来源于stack exchange,提问作者Ramesh
相关产品推荐
相关产品推荐

