Skip to content

Commit ae2497f

Browse files
committed
Correctly loads JSON files with UTF-8 encoding
1 parent 740d1da commit ae2497f

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

model_inventory.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ def extract_services(input_dir: Path):
77
service_entries = []
88
for model_file in input_dir.glob("*.json"):
99
try:
10-
with open(model_file, "r") as f:
10+
with open(model_file, "r", encoding="utf-8") as f:
1111
model_data = json.load(f)
1212

1313
shapes = model_data.get("shapes", model_data)
@@ -25,6 +25,18 @@ def extract_services(input_dir: Path):
2525
"servicename": shape_name,
2626
"protocol": protocol
2727
})
28+
except json.JSONDecodeError as e:
29+
service_entries.append({
30+
"filename": model_file.name,
31+
"servicename": "ERROR",
32+
"protocol": f"JSON decode error: {e}"
33+
})
34+
except UnicodeDecodeError as e:
35+
service_entries.append({
36+
"filename": model_file.name,
37+
"servicename": "ERROR",
38+
"protocol": f"Encoding error: {e}"
39+
})
2840
except Exception as e:
2941
service_entries.append({
3042
"filename": model_file.name,

process_models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
def extract_services(input_dir: Path):
1717
for model_file in input_dir.glob("*.json"):
1818
try:
19-
with open(model_file, "r") as f:
19+
with open(model_file, "r", encoding="utf-8") as f:
2020
model_data = json.load(f)
2121

2222
shapes = model_data.get("shapes", model_data)

processors/rest_json1.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def process(model_entry):
4141

4242
model_path = Path(model_entry['filepath'])
4343

44-
with open(model_path, "r") as f:
44+
with open(model_path, "r", encoding="utf-8") as f:
4545
model_data = json.load(f)
4646

4747
# Basic OpenAPI structure

0 commit comments

Comments
 (0)