Repository navigation
Expand file tree
/
Copy pathutils.py
More file actions
41 lines (34 loc) · 1.33 KB
/
Copy pathutils.py
File metadata and controls
41 lines (34 loc) · 1.33 KB
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
import json
import importlib
from typing import Dict, Any
def load_requirements(file_path: str) -> str:
"""Load requirements from a file."""
with open(file_path, 'r') as file:
return file.read()
def load_schema(file_path: str) -> Dict[str, Any]:
"""Load JSON schema from a file."""
with open(file_path, 'r') as file:
return json.load(file)
# Aliases and unique properties
with open('data_model/aliases.json') as f:
aliases = json.load(f)
with open('data_model/unique_properties.json') as f:
unique_properties = json.load(f)
module_name = "data_model.building"
module = importlib.import_module(module_name)
def clean_json(data):
"""Remove null and 'null' values from JSON data."""
if isinstance(data, dict):
return {k: clean_json(v) for k, v in data.items() if v is not None and v != "null"}
elif isinstance(data, list):
return [clean_json(v) for v in data if v is not None and v != "null"]
else:
return data
def process_json_result(result: str) -> Dict[str, Any]:
"""Process and clean the JSON result."""
try:
epjson_content = json.loads(result.replace("```json", "").replace("```", ""))
clean_json(epjson_content)
return epjson_content
except json.JSONDecodeError:
raise ValueError("The generated content is not valid JSON.")