0

鑑於以下JSON對象,我該如何構建json模式? Product1,Product2和Product3是動態的「鍵」,我可以有更多類似的內容,但它們中的每一個都將具有與packageId1,packageId2,packageId3及其對應的值作爲字符串所需的鍵相同的「value」對象。基於json對象創建JSON模式

{ 
    "Product1": { 
    "packageId1": "basicpackage", 
    "packageId2": "basicpackage", 
    "packageId3": "basicpackage" 
    }, 
    "Product2": { 
    "packageId1": "newpackage", 
    "packageId2": "newpackage", 
    "packageId3": "newpackage" 
    }, 
    "Product3": { 
    "packageId1": "thirdpackage", 
    "packageId2": "thirdpackage", 
    "packageId3": "thirdpackage" 
    } 
} 

回答

1

我想我該怎麼做。如果有人有興趣,我正在回答我自己的問題。另外,我歡迎更好的建議。

{ 
    "title": "JSON Schema for Fulfillment Config", 
    "$schema": "http://json-schema.org/draft-04/schema#", 
    "type": "object", 
    "patternProperties": { 
    ".{1,}": { 
     "type": "object", 
     "properties": { 
     "packageId1": { "type": "string" }, 
     "packageId2": { "type": "string" }, 
     "packageId3": { "type": "string" } 
     } 
    } 
    } 
}