-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path5_validateJSONs.py
42 lines (34 loc) · 1.3 KB
/
5_validateJSONs.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
38
39
40
41
42
# Validates a JSON file against the OGM Aardvark JSON schema.
# Designed to validate the output from parseCSVToMultipleJSONs.py.
# Import the required libraries
import json
import jsonschema
from jsonschema import validate
import os
# Define the JSON schema file
with open('./helper_docs/geoblacklight-schema-aardvark.json', 'r') as s:
aardvarkSchema = json.load(s)
# Start the counter
record_count = 0
# Create a variable to store error messages
error = None
# Iterate through JSON files in the directory
for file in os.listdir('.'):
if file.endswith('.json'):
# Increase the count each time a file is processed
record_count = record_count + 1
# Open an individual file and make sure to close it when done processing
with open(file, 'r') as f:
# Read the JSON file
geoJSON = json.load(f)
# Validate the JSON file
try:
validate(instance=geoJSON, schema=aardvarkSchema)
except jsonschema.exceptions.ValidationError as err:
print("Error identified in", file, ":")
print(err)
error = err
if error is not None:
print("WARNING: There is an error in one or more of the records. See above for details.")
else:
print("All ", record_count, " records are valid.")