import json


def load_json_file(json_path, logger=None, encoding=None):
    """Load a JSON file, possibly logging errors.

    Parameters
    ----------
        json_path : path_like
            Relative path to the JSON file.

        logger : logging.Logger (optional, default None)
            Logger to use.

        encoding : str (optional, default None)
            Encoding to use.  None means system preferred encoding.

    Returns
    -------
        contents : dict
            Contents of the JSON file.

    """
    try:
        with open(json_path, 'r', encoding=encoding) as json_file:
            contents = json.load(json_file)
    except OSError as e:
        if logger is not None:
            logger.error("Could not open {}: {}".format(json_path, e))
        raise
    except ValueError as e:
        if logger is not None:
            logger.error("Could not load {}: {}".format(json_path, e))
        raise

    return contents