import importlib
import json


def create_object(config):
    """
    Creates an object from the specified configuration dictionary.
    Its format is:

        class: The fully qualified path name.
        args: A list of positional arguments (optional).
        kwargs: A dictionary of keyword arguments (optional).
    """
    try:
        module_name, _, class_name = config['class'].rpartition('.')
        module = importlib.import_module(module_name)
        cls = getattr(module, class_name)
        return cls(*config.get('args', []), **config.get('kwargs', {}))
    except Exception as e:
        raise Exception(
            'Could not create object\n{}'.format(json.dumps(config, indent=4)),
            e
        )