On php, I just use json_encode() and json_decode() to handle JSON data with ease. Python has a built in module named “json” for the same purpose. Here’s the link for the official documentation: http://docs.python.org/library/json.html
The documentation has pretty examples. Still, I wanted to try things out by myself. I used Python to parse the JSON output of a certain Yahoo! Pipes feed :
import json,urllib data = urllib.urlopen("http://pipes.yahoo.com/pipes/pipe.run?_id=a0b9e3295664870ee81711aed6f7ecd6&_render=json").read() d = json.loads(data) for x in d['value']['items']: print x['title']
Output:
masnun@ubuntu:~/Desktop$ python jsontest.py Sms Plugin .......... [SNIP] .......... Profit Spreadsheet Graphic Web Des. Needed Fast Customer Ordering Website Dating Site Profiles masnun@ubuntu:~/Desktop$
Pingback: Tweets that mention Handling JSON in Python « maSnun.com -- Topsy.com