Created
October 18, 2011 05:25
-
-
Save Gunio/1294675 to your computer and use it in GitHub Desktop.
Parsing JSON in python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import simplejson | |
r = requests.get('https://github.com/timeline.json') | |
c = r.content | |
j = simplejson.loads(c) | |
for item in j: | |
print item['repository']['name'] |
Why not just r.json()
? Reference: http://docs.python-requests.org/en/latest/user/quickstart/#json-response-content
Code could be further simplified using r.json()
. Below is an example to parse @harishvc Github public timeline.
import requests
import simplejson
#python 3.x
r = requests.get('Https://api.github.com/users/harishvc/events/public')
for item in r.json():
for c in item['payload']['commits']:
print(c['sha'], c['message'])
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How can I parse a value of "raw_url" and "content"? in https://api.github.com/gists/6386902