import json, os def load_json(file_path): if os.path.exists(file_path): with open(file_path, "r") as f: try: return json.load(f) except json.JSONDecodeError: return [] return [] def save_json(file_path, data): os.makedirs(os.path.dirname(file_path), exist_ok=True) with open(file_path, "w") as f: json.dump(data, f, indent=4)