-
Notifications
You must be signed in to change notification settings - Fork 4
/
check_schema.py
39 lines (34 loc) · 1.2 KB
/
check_schema.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from jsonschema import validate, ValidationError
import json
import sys
def check(to_check, schema="schema.json"):
with open(schema, "r") as schema_file:
d = json.load(schema_file)
print(d)
node_schema = d["node_schema"]
edge_schema = d["edge_schema"]
with open(to_check, "r") as to_check_file:
data = json.load(to_check_file)
try:
validate(data, edge_schema) # edge schema more restrictive; check this first
except ValidationError as edge_except:
try:
validate(data, node_schema)
except ValidationError as node_except:
print("File not valid")
print(edge_except)
print(node_except)
return
print("Valid node")
return
print("Valid edge")
return
print("Something went wrong.")
if __name__ == "__main__":
if len(sys.argv) < 2:
print("Usage: python check_schema file_to_check.json [schema.json]")
exit(0)
if len(sys.argv) == 3:
check(sys.argv[1], sys.argv[2])
else:
check(sys.argv[1])