import json


def to_json(grouped_routes):
    """
    Convert list of :class:`RouteGroup` objects in `grouped_routes` to JSON.

    Args:
        grouped_routes (list): Llist of :class:`RouteGroup` objects.

    Returns:
        str: JSON representation of `grouped_routes`.
    """
    routes = map(
        lambda x: x.to_dict(),
        grouped_routes
    )

    return json.dumps(
        routes,
        indent=4,
        separators=(',', ': ')
    )