Source code for pi_portal.modules.mixins.json_file

"""JSONFile mixin classes."""

import json
from pathlib import Path
from typing import Any, Union


[docs]class JSONFileReader: """JSONFileReader mixin class.""" encoding = "utf-8"
[docs] def load_json_file(self, json_file_location: Union[Path, str]) -> Any: """Load a JSON file from the filesystem and return it as a Python object. :param json_file_location: The path to the source file. :returns: The loaded JSON object. """ with open(json_file_location, encoding=self.encoding) as fhandle: json_file_content = json.load(fhandle) return json_file_content