from typing import OrderedDict


def orderify(obj):
    """Convert dicts (recursively) to ordered dicts with sorted keys"""

    if isinstance(obj, dict):
        for key, value in obj.items():
            if isinstance(value, dict):
                obj[key] = orderify(value)
                continue
            if isinstance(value, (tuple, list)):
                obj[key] = orderify(value)
        obj = OrderedDict((key, obj[key]) for key in sorted(obj.keys()))
    elif isinstance(obj, (tuple, list)):
        obj = type(obj)(sorted((orderify(v) for v in obj),
                               key=str))

    return obj