(filepath: Union[str, pathlib.Path])
| 116 | |
| 117 | @staticmethod |
| 118 | def load_json(filepath: Union[str, pathlib.Path]) -> Union[List[Any], Dict[str, Any]]: |
| 119 | if isinstance(filepath, str): |
| 120 | filepath: pathlib.Path = pathlib.Path(filepath) |
| 121 | |
| 122 | result = [] |
| 123 | if not filepath.exists(): |
| 124 | log.debug(f"Unable to load json from {filepath.absolute()}. Does not exist.") |
| 125 | return result |
| 126 | elif filepath.is_dir(): |
| 127 | log.debug(f"Cannot load json at path {filepath.absolute()}. It is a directory") |
| 128 | return result |
| 129 | |
| 130 | with open(filepath, "r", encoding="utf-8-sig") as fp: |
| 131 | try: |
| 132 | result = json.load(fp) |
| 133 | if not result: |
| 134 | return [] |
| 135 | except json.decoder.JSONDecodeError as err: |
| 136 | log.debug(f"JSONDecodeError while processing {filepath.absolute()} \n error: {str(err)}") |
| 137 | return [] |
| 138 | except UnicodeDecodeError as err: |
| 139 | log.debug(f"UnicodeDecodeError while processing {filepath.absolute()} \n error: {str(err)}") |
| 140 | return [] |
| 141 | return result |
| 142 | |
| 143 | @staticmethod |
| 144 | def write_json(filepath: Union[str, pathlib.Path], content: Dict[str, Any]) -> None: |
no outgoing calls
no test coverage detected