Download JSON data and convert it to CSV using Python

I am currently using Yahoo Pipes, which provides me with a JSON file with a URL.

I would like to get it and convert it to a CSV file, and I don't know where to start (I'm a complete newbie in Python).

How can I get JSON data from a URL?
How to convert it to CSV?

thank

+3
source share
1 answer
import urllib2
import json
import csv

def getRows(data):
    # ?? this totally depends on what in your data
    return []

url = "http://www.yahoo.com/something"
data = urllib2.urlopen(url).read()
data = json.loads(data)

fname = "mydata.csv"
with open(fname,'wb') as outf:
    outcsv = csv.writer(outf)
    outcsv.writerows(getRows(data))
+4
source

All Articles