import json


def _get_type_from_str(str, default=None):
    """
    Convert docstring into object suitable for inclusion as documentation. It
    tries to parse the docstring as JSON, falling back on provided default
    value.
    """
    if str:
        try:
            return json.loads(str)
        except ValueError:
            pass
    return default if default is not None else str