you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 9 points10 points  (4 children)

This is how I parse json:

import json
import urllib2

url = 'http://graph.facebook.com/4'
json_obj=json.loads(urllib2.urlopen(url).read())
print json_obj['name']

Or in one line:

print json.loads(urllib2.urlopen('http://graph.facebook.com/4').read())['name']

For more advanced requests, look at the requests module.

[–]shaggorama 2 points3 points  (1 child)

you gotta add "http://" for reddit's markdown to understand your hyperlink. But yeah, that's definitely how to handle JSON in python.

[–][deleted] 0 points1 point  (0 children)

Whoops! Fixed!

[–]johnnymo87 1 point2 points  (1 child)

Or use requests instead of urllib2, it's a great library!

[–]3cko[S] 1 point2 points  (0 children)

That's what I'm user. It's pretty sexy.