[英]Creating a hierarchy of JSON schemas
我正在使用來自不同類型的源的信息來構造一些JSON數據。 我只關注一種類型的源文檔,我收集並准備好了一些數據點。 所以我決定嘗試為有關文檔的數據編寫JSON模式。
無論源的類型如何,前四個屬性(id,name,type和url)都必須存在,但每個屬性中包含的其他信息會有所不同。 我想將所有這些存儲在同一個數據庫中。 我想在以后為每個其他類型的源編寫一個模式會很有意義。
我很擅長使用JSON,目前的難點在於理解如何將這些模式整合在一起。 什么是最佳做法? 是否可以使用包含以下信息的頂級模式和每種類型的二級模式創建這些不同對象類型的層次結構? 或者,更好地制作一個更大的模式,其中包含可能存在於所有不同類型的源中的所有信息?
"$schema": "http://json-schema.org/schema#",
"title": "Document",
"description": "Information connected to a document",
"type": "object",
"properties": {
"id": {
"description": "The unique identifier",
"type": "number"
},
"name": {
"description": "Title of the source",
"type": "string"
},
"type": {
"description": "Type of source",
"type": "string"
},
"url": {
"description": "URL of the source",
"type": "string"
},
"morePropertiesHere": {
"description": "the rest of the properties vary depending on type of source"
}
},
"required": ["id", "name", "type", "url"]
您可以像這樣更改JSON中的屬性部分,因為它只需要數字和文本。
“properties”:{“id”:1234,“name”:“源名稱”,“description”:“源名稱”,“類型”:“源類型”,“url”:“URL來源”,
“morePropertiesHere”:{“description”:“其余屬性因源類型而異”}}如果Id是數字,那么您可以按原樣提供它們而不是放入“”。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.