Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 13891

How do I extract the data from the response.json output from an API call?

$
0
0

I looped through a json file and then used the corresponding data taken from the json file to obtain phone numbers using a skip tracing API. I have the response.json printed out after making the API call. How can I take the data that was output and put it into a dataframe? Do I need to change the code and make the API call again, or can I do this without making another API call? See attached picture and code below:

code with output shown

# Define the API endpointurl = "https://skip-trace1.p.rapidapi.com/byAddress"# Define headers for the API requestheaders = {"X-RapidAPI-Key": "notshownhere","X-RapidAPI-Host": "notshown"}# Iterate through the data in the JSON filefor item in data:    # Extract streetAddress, city, and state from each item    street_address = item["Address"]    city = item["City"]    state = item["State"]    # Define the query parameters    querystring = {"streetAddress": street_address, "city": city, "state": state}    # Make the API request    response = requests.get(url, headers=headers, params=querystring)    # Print the API response    print(response.json())

I have tried taking the response.json and saving it into a json file, but I have gotten errors. I can't seem to access the info obtained from printing the response.json again.


Viewing all articles
Browse latest Browse all 13891

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>