2016-04-29 27 views
2

小さなチャンクos jsonスキーマを記述しましたが、python jsonschemaを使用して検証エラーが発生しました。ここで'type' jsonスキーマの検証に失敗しました

は私のスキーマです:ここでは

{ 


"$schema": "http://json-schema.org/draft-04/schema#", 
    "definitions": { 
    "output": { 
     "type": "object", 
     "properties": { 
     "Type": { 
      "type": "object", 
      "properties": { 
      "Type": { 
       "type": "string" 
      }, 
      "Value": { 
       "type": "string" 
      }, 
      "Default": { 
       "type": "string" 
      }, 
      "Description": { 
       "type": "string" 
      }, 
      "Options": { 
       "type": "array" 
      } 
      }, 
      "required": [ 
      "Type", 
      "Value", 
      "Default", 
      "Description", 
      "Options" 
      ] 
     }, 
     "Inverted": { 
      "type": "object", 
      "properties": { 
      "Type": { 
       "type": "string" 
      }, 
      "Value": { 
       "type": "bool" 
      }, 
      "Default": { 
       "type": "bool" 
      }, 
      "Description": { 
       "type": "string" 
      } 
      }, 
      "required": [ 
      "Type", 
      "Value", 
      "Default", 
      "Description" 
      ] 
     }, 
     "Pulse Width": { 
      "type": "object", 
      "properties": { 
      "Type": { 
       "type": "string" 
      }, 
      "Value": { 
       "type": "number" 
      }, 
      "Default": { 
       "type": "number" 
      }, 
      "Description": { 
       "type": "string" 
      } 
      }, 
      "required": [ 
      "Type", 
      "Value", 
      "Default", 
      "Description" 
      ] 
     } 
     }, 
     "required": [ 
     "Type", 
     "Inverted", 
     "Pulse Width" 
     ] 
    } 
    } 
} 

は、私が受けてるのエラーです:

Failed validating u'type' in schema 

私は自分のスキーマを検証しようとしています:

schema = "" 
with open(jsonSchemaFilePath, 'r') as schema_file: 
    schema = schema_file.read() 

try: 
    Draft4Validator.check_schema(schema) 
except SchemaError as schemaError: 
    print schemaError 

何私が書いたスキーマに間違っているのですか? Typeという名前のプロパティを持つことは許されませんか?

+0

:ここ

は、私の解決策でした。私は自分のJSONを自分のシェルにロードしようとしましたが、うまくいきました。 'check_schema'はjsonオブジェクトを期待していますか? –

+0

'check_schema'が' dic'を探していた – visc

+0

嬉しいです。あなたはあなたの答えを正しいものとしてマークしてください! –

答えて

1

私の問題はDraft4Validator.check_schemaです。dicは文字列でもjsonオブジェクトでもありません。私の以前のコメントが間違っていた

schema = {} 
with open(jsonSchemaFilePath, 'r') as schema_file: 
    schema = json.loads(schema_file.read()) 

try: 
    Draft4Validator.check_schema(schema) 
except SchemaError as schemaError: 
    print schemaError 
関連する問題