MCPcopy Create free account
hub / github.com/LOLINTERNETZ/vscodeoffline / load_json

Method load_json

vscoffline/vsc.py:118–141  ·  view source on GitHub ↗
(filepath: Union[str, pathlib.Path])

Source from the content-addressed store, hash-verified

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:

Callers 4

on_getMethod · 0.80
on_getMethod · 0.80
update_stateMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected