Handling JSON in Python

Saturday, January 30th, 2010

Tags:

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$

One Response to “Handling JSON in Python”

  1. [...] This post was mentioned on Twitter by Abu Ashraf Masnun, Telletto. Telletto said: maSnun says… Handling JSON in Python: On php, I just use json_encode() and json_decode() to handle JSON data wit… http://bit.ly/aGfmoB [...]

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">