load_json
- pyhelpers.store.load_json(path_to_json, engine=None, verbose=False, **kwargs)
Load data from a JSON file.
- Parameters
path_to_json (str or os.PathLike[str]) – path where a json file is saved
engine (str or None) – an open-source Python package for JSON serialization, options include
None
(default, for the built-in json module),'ujson'
(for UltraJSON),'orjson'
(for orjson) and'rapidjson'
(for python-rapidjson)verbose (bool or int) – whether to print relevant information in console, defaults to
False
kwargs – [optional] parameters of json.load() (if
engine=None
), orjson.loads() (ifengine='orjson'
), ujson.load() (ifengine='ujson'
) or rapidjson.load() (ifengine='rapidjson'
)
- Returns
data retrieved from the specified path
path_to_json
- Return type
dict
Note
Example data can be referred to the function
pyhelpers.store.save_json()
.
Examples:
>>> from pyhelpers.store import load_json >>> from pyhelpers.dirs import cd >>> json_path = cd("tests\data", "dat.json") >>> json_dat = load_json(json_path, verbose=True) Loading "tests\data\dat.json" ... Done. >>> json_dat {'London': {'Longitude': -0.1276474, 'Latitude': 51.5073219}, 'Birmingham': {'Longitude': -1.9026911, 'Latitude': 52.4796992}, 'Manchester': {'Longitude': -2.2451148, 'Latitude': 53.4794892}, 'Leeds': {'Longitude': -1.5437941, 'Latitude': 53.7974185}}