-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathvalidate_json.py
36 lines (34 loc) · 922 Bytes
/
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
import json
import jsonschema
import sys
import glob
# JSON schema
schema = {
"type": "object",
"required": ["mods", "desc", "name", "authors"],
"properties": {
"mods": {
"type": "array",
"items": {
"type": "string"
}
},
"desc": {"type": "string"},
"name": {"type": "string"},
"authors": {
"type": "array",
"items": {
"type": "string"
}
}
}
}
# Validate JSON files
for file_path in glob.glob("**/*.json", recursive=True):
with open(file_path) as f:
try:
json_data = json.load(f)
jsonschema.validate(instance=json_data, schema=schema)
except (json.JSONDecodeError, jsonschema.exceptions.ValidationError) as e:
print(f"{file_path}: {e}")
sys.exit(1)