-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathvalidate.py
More file actions
30 lines (26 loc) · 848 Bytes
/
validate.py
File metadata and controls
30 lines (26 loc) · 848 Bytes
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
import sys
import json
from jsonschema import validate, ValidationError
def load_schema():
with open('video_label.schema.json', 'r') as f:
schema_string = f.read()
schema = json.loads(schema_string)
return schema
def get_input_iter():
for i, line in enumerate(sys.stdin, 1):
try:
yield json.loads(line)
except json.decoder.JSONDecodeError:
sys.stderr.write(
'Failed to decode JSON object at line %d: "%s"\n' % (i, line))
def main():
schema = load_schema()
for i, obj in enumerate(get_input_iter(), 1):
try:
validate(obj, schema)
except ValidationError as e:
sys.stderr.write(
'Validation error at line %d:\n"%s"\n' % (i, json.dumps(obj)))
print('Done.')
if __name__ == '__main__':
main()