-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathverify_sgpt_json.py
42 lines (34 loc) · 1.11 KB
/
verify_sgpt_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
38
39
40
41
42
import json
import sys
def is_valid_structure(data):
# Check if the structure matches the expected format
if not isinstance(data, list):
return False
for item in data:
if not isinstance(item, dict) or "id" not in item or "conversations" not in item:
return False
conv = item["conversations"]
if not isinstance(conv, list):
return False
for msg in conv:
if not isinstance(msg, dict) or "from" not in msg or "value" not in msg:
return False
return True
def main(input_file):
# Read JSON file
with open(input_file, 'r') as file:
try:
data = json.load(file)
except json.JSONDecodeError as e:
print(f"Error decoding JSON file: {e}")
return
# Check if the structure is valid
if is_valid_structure(data):
print("JSON structure is valid.")
else:
print("Error: Invalid JSON structure.")
if __name__ == "__main__":
if len(sys.argv) != 2:
print("Usage: python validate_json.py <input_file.json>")
else:
main(sys.argv[1])