forked from CleverRaven/Cataclysm-DDA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalidate_json.py
executable file
·37 lines (31 loc) · 1.04 KB
/
validate_json.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
#!/usr/bin/env python3
# Validate that all JSON files are syntactically correct;
# does NOT check indentation styles.
import glob
import json
import sys
def main():
json_files = glob.glob('**/**.json', recursive=True)
errors = 0
total = 0
for file_path in json_files:
if not file_path.startswith("android/app/src/main/assets"):
total += 1
try:
with open(file_path, encoding="utf-8") as fp:
_ = json.load(fp)
except OSError as e:
print("Error opening {}: {}".format(file_path, e))
errors += 1
except json.JSONDecodeError as e:
print("Error parsing {}: {}".format(file_path, e))
errors += 1
if errors == 0:
print("All {} JSON files healthy.".format(total))
return 0
else:
print("Found {} erroneous files among {} JSON files in the repository."
.format(errors, total))
return min(errors, 255)
if __name__ == '__main__':
sys.exit(main())