def parse_affiliations(response):
    """Parse the author affiliations from a MAG API response.

    Args:
        response (json): Response from MAG API in JSON format. Contains all paper information.

    Returns:
        affiliations (:obj:`list` of :obj:`dict`): List of dictionaries with affiliation information.
            There's one dictionary per field of study.
       author_with_aff (:obj:`list` of :obj:`dict`): Matching affiliation and author IDs.

    """
    affiliations = []
    author_with_aff = []
    for aff in response["AA"]:
        if aff["AfId"]:
            # mag_author_affiliation
            author_with_aff.append(
                {"affiliation_id": aff["AfId"], "author_id": aff["AuId"]}
            )
            # mag_affiliation
            affiliations.append({"id": aff["AfId"], "affiliation": aff["AfN"]})
        else:
            continue
    return affiliations, author_with_aff