Skip to content

Instantly share code, notes, and snippets.

@jacek64
Created February 6, 2016 21:03
Show Gist options
  • Save jacek64/1a67407e68e1f50c75b4 to your computer and use it in GitHub Desktop.
Save jacek64/1a67407e68e1f50c75b4 to your computer and use it in GitHub Desktop.
Load Json into a Python object
# Load Json into a Python object
import urllib2
import json
req = urllib2.Request("http://localhost:81/sensors/temperature.json")
opener = urllib2.build_opener()
f = opener.open(req)
json = json.loads(f.read())
print json
print json['unit']
# Array example
import urllib2
import json
req = urllib2.Request("http://vimeo.com/api/v2/video/38356.json")
opener = urllib2.build_opener()
f = opener.open(req)
json = json.loads(f.read())
print json
print json[0]['title']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment