Get JSON

json is a module that helps us use the JSON data format.


In [ ]:
import json

requests is a third-party module for interacting with the Internet


In [ ]:
import requests

Set the URL of the data, which we've mirrored here on S3: https://s3.amazonaws.com/nicar17/pycar17/bill_track.json (You can find the original data here)


In [ ]:
url = 'https://s3.amazonaws.com/nicar17/pycar17/bill_track.json'

Read the requests documentation for information. I promise it isn't that scary. http://docs.python-requests.org/en/latest/user/quickstart/#json-response-content

Request the data


In [ ]:
r = requests.get(url)

Since we know our data will be JSON, let's automatically convert it to a Python dict.


In [ ]:
data = r.json()

-- OR --

If the network is down, we can use a local version of this file.

with open('bills.json', 'r') as f:
    data = json.load(f)

json.dumps() is a way to print a Python dict in a more human-readable way.


In [ ]:
print(json.dumps(data, indent=4))