2013-05-08 64 views
1

假設我正在編寫JSON模式。 「類型」是「對象」。在對象的「屬性」中包含名爲「description」的屬性是否合法?我問,因爲「description」是JSON模式中的關鍵字。「description」是JSON模式中對象的有效「屬性」嗎?

例如:在這個例子中,我提出了一個簡單的JSON對象表示葡萄酒年份的模式。我指定了四個屬性:三個必需屬性(房子,年份和葡萄品種)和一個可選屬性,名爲「描述」。

{ 
    "$schema": "http://json-schema.org/draft-04/schema#", 
    "title": "Wine vintage", 
    "description": "JSON schema for wine vintages", 
    "type": "object", 
    "properties": { 
     "house": { 
      "description": "The name of the house that made the wine", 
      "type": "string" 
     }, 
     "year": { 
      "description": "The year in which the wine was made", 
      "type": "integer" 
     }, 
     "varieties": { 
      "description": "The grape varieties used to make the wine", 
      "type": "array", 
      "items": { 
       "type": "string", 
       "minItems": 1, 
       "uniqueItems": true 
      } 
     } 
     "description": { 
      "description": "A description of the wine's taste and character; a tasting note", 
      "type": "string" 
     } 
    }, 
    "required": ["house", "year", "varieties"] 
} 

回答

2

我認爲這是合法的。在spec中我沒有看到任何明確禁止定義與模式關鍵字相同的對象屬性名稱的任何內容。 (此外,如果確實如此,像「id」,「type」和「items」這樣有用且常見的詞語也將作爲屬性名稱被禁止)。

1

"properties"中的鍵沒有任何特殊含義。你可以在那裏使用任何東西:"id""description",甚至"$ref"

模式關鍵字在模式對象內部只有直接纔有特殊含義。