import json


def convert_json_to_dict(json_data):
    """Converts JSON data containing location info on an IP address to a Python dictionary"""
    loc_dict = {}
    # Replace default key:'ip' with new key:'source_ip' to match the other data
    new_key = "source_ip"
    old_key = "ip"

    try:
        loc_dict = json.loads(json_data)
        loc_dict[new_key] = loc_dict.pop(old_key)

        for current_key in loc_dict.keys():
            if current_key != "source_ip":
                new_key = "ip_" + current_key
                loc_dict[new_key] = loc_dict.pop(current_key)

    except ValueError:  # includes simplejson.decoder.JSONDecodeError
        print("\n[!] ERROR -> Loading Location JSON data has failed")

    return loc_dict