Handling JSON in Python

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$
Tags: . Bookmark the permalink.

One Response to Handling JSON in Python

  1. Pingback: Tweets that mention Handling JSON in Python « maSnun.com -- Topsy.com

Leave a Reply

Your email address will not be published. Required fields are marked *

*

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