blob: 12d5d8566f12ca19ae60fc93b4c304138ab020ef [file] [log] [blame]
LiamBurke4d438ce2019-02-14 13:24:52 +00001# -*- coding: utf-8 -*-
2
3import sys
4import logging
5from simplejson import load
6from jsonschema import validate, ValidationError, SchemaError
7
8
9class JsonValidatorLibrary(object):
10
11 def __init__(self):
12 pass
13
14 def validate(self, schemaPath, jsonPath):
15 logging.info("Schema path: " + schemaPath)
16 logging.info("JSON path: " + jsonPath)
17 schema = None
18 data = None
19 try:
20 schema = load(open(schemaPath, 'r'))
21 data = load(open(jsonPath, 'r'))
22 except (IOError, ValueError, OSError) as e:
23 logging.error(e.message)
24 return 1
25
26 try:
27 validate(data, schema)
28 except (ValidationError, SchemaError) as e:
29 logging.error(e.message)
30 return 1
31
32 # logger.log("JSON validation successful")
33 print("JSON validation successful")
34 return 0
35
36if __name__ == '__main__':
37 lib = JsonValidatorLibrary()
38 # sys.exit(JsonValidatorLibrary().validate(sys.argv[1], sys.argv[2]))