def sort_nested_dict(d):
    """Alphabetize keys in nested dict, including dicts inside lists."""
    if isinstance(d, dict):
        return {k: sort_nested_dict(v) for k, v in sorted(d.items())}
    if isinstance(d, (list, tuple)):
        return [sort_nested_dict(v) for v in d]
    return d