import json import pandas as pd import requests # Pull down some simple json data r = requests.get('http://api.zippopotam.us/us/ma/belmont') # Convert it into a python object data = r.json() # View the data data # One level deep data['places'] # One level deep, second element data['places'][1] # One level down, then second item, then it's longitude object data['places'][1]['longitude'] # For each element, i, in data.places, for i in data['places']: # print the latitude element and the longitude element print(i['latitude'], i['longitude']) # Create a function that def extract_latlong(json): # For each element, i, in data.places, for i in data['places']: # print the latitude element and the longitude element print(i['latitude'], i['longitude']) # Run the function extract_latlong(data)