def json_for_user(user, session_id):
    """ Convert the provided user to a dictionary (for JSON)

        Args:
            user: the User object

        Returns:
            An object containing user details
    """
    return {
        "user_id": user.user_id,
        "name": user.name,
        "title": user.title,
        "skip_guide": user.skip_guide,
        "website_admin": user.website_admin,
        "affiliations": [{"agency_name": affil.cgac.agency_name, "permission": affil.permission_type_name}
                         if affil.cgac else
                         {"agency_name": affil.frec.agency_name, "permission": affil.permission_type_name}
                         for affil in user.affiliations],
        "session_id": session_id
    }