def _generate_preset_groups_element(*, field):
    """Generate the JSON specification for a ``preset_groups`` flavor of
    a ``select`` element.
    """
    option_groups = []
    for group in field["preset_groups"]:
        menu_group = {"label": group["group_label"], "options": []}
        for group_option in group["options"]:
            menu_group["options"].append(
                {
                    "label": group_option["label"],
                    "value": group_option["label"],
                }
            )
        option_groups.append(menu_group)
    element = {
        "label": field["label"],
        "type": "select",
        "name": field["label"],
        "option_groups": option_groups,
        "optional": field["optional"],
    }
    return element