Load connection credential from json file.

        :param json_file: str, path to json file
        :param json_path: str, dot notation of the path to the credential dict.
        :param key_mapping: dict, map 'host', 'port', 'database', 'username', 'password'
            to custom alias, for example ``{'host': 'h', 'port': 'p', 'database': 'db', 'username': 'user', 'password': 'pwd'}``. This params are used to adapt any json data.

        :rtype:
        :return:

        Example:

        Your json file::

            {
                "credentials": {
                    "db1": {
                        "h": "example.com",
                        "p": 1234,
                        "db": "test",
                        "user": "admin",
                        "pwd": "admin",
                    },
                    "db2": {
                        ...
                    }
                }
            }

        Usage::

            cred = Credential.from_json(
                "path-to-json-file", "credentials.db1",
                dict(host="h", port="p", database="db", username="user", password="pwd")
            )

def from_json(cls, json_file, json_path=None, key_mapping=None):
        """
        Load connection credential from json file.

        :param json_file: str, path to json file
        :param json_path: str, dot notation of the path to the credential dict.
        :param key_mapping: dict, map 'host', 'port', 'database', 'username', 'password'
            to custom alias, for example ``{'host': 'h', 'port': 'p', 'database': 'db', 'username': 'user', 'password': 'pwd'}``. This params are used to adapt any json data.

        :rtype:
        :return:

        Example:

        Your json file::

            {
                "credentials": {
                    "db1": {
                        "h": "example.com",
                        "p": 1234,
                        "db": "test",
                        "user": "admin",
                        "pwd": "admin",
                    },
                    "db2": {
                        ...
                    }
                }
            }

        Usage::

            cred = Credential.from_json(
                "path-to-json-file", "credentials.db1",
                dict(host="h", port="p", database="db", username="user", password="pwd")
            )
        """
        cls._validate_key_mapping(key_mapping)
        with open(json_file, "rb") as f:
            data = json.loads(f.read().decode("utf-8"))
            return cls._from_json_data(data, json_path, key_mapping)