How to load JSON from url using Python?

/ #Python


If you want to get JSON from a website you need to import a few libraries and run a request. Here's how you do it.

# Import libraries
import urllib.request, json 

# Get json from url
with urllib.request.urlopen("http://maps.googleapis.com/maps/api/geocode/json?address=Oslo") as url:
    # Load JSON
    data = json.loads(url.read().decode())

    # Print data
    print(data)

Comments

No comments yet...

Add comment

Info

Please log in to comment!

Newsletter

Subscribe to my weekly newsletter. One time per week I will send you a short summary of the tutorials I have posted in the past week.