2016-11-18 8 views
1

の配列中に存在している私はこのようなJSONスキーマ持っJSONスキーマのチェックすべての項目の列挙型は、オブジェクト

[ 
    {"country": "aa"}, 
] 

を私はスキーマがJSONかどうかを確認したいですファイルに列挙されているすべての国が含まれています:

[ 
    {"country": "aa"}, 
    {"country": "bb"}, 
] 

可能でしょうか?

{ 
    "allOf": [ 
    { "contains": { "properties": { "country": { "constant": "aa" } } } }, 
    { "contains": { "properties": { "country": { "constant": "bb" } } } } 
    ] 
} 

"constant": "aa""enum": ["aa"]と同じ別のV5/6キーワード、次のとおりです。あなたがV5/6でそれを行うことができます

答えて

1

は、キーワードが含まれています。 現在、Ajvはこれらのキーワードをサポートしています(自己宣伝のビット)。 @esp便利な構文を使用することができない人のために

+0

は、それらのものを明確にしていただきありがとうございます) – xdrew

1

は、ここでは古いスタイルのソリューションです:

{ 
    "$schema": "http://json-schema.org/draft-04/schema#", 
    "type": "array", 
    "items": { 
     "type": "object", 
     "properties": { 
      "country": { 
       "type": "string", 
       "maxLength": 2, 
       "enum": ["aa", "bb"] 
      } 
     }, 
     "required": [ 
      "country" 
     ] 
    }, 
    "allOf": [ 
     {"not": {"items": {"not": {"properties": {"country": {"enum": ["aa"]}}}}}}, 
     {"not": {"items": {"not": {"properties": {"country": {"enum": ["bb"]}}}}}} 
    ] 
} 
関連する問題