def json2csv(fp, outfile, fields, encoding='utf8', errors='replace', gzip_compress=False):
 (writer, outf) = outf_writer_compat(outfile, encoding, errors, gzip_compress)
 writer.writerow(fields)
 for line in fp:
  tweet = json.loads(line)
  row = extract_fields(tweet, fields)
  writer.writerow(row)
 outf.close()

def json2csv ( fp , outfile , fields , encoding = 'utf8' , errors = 'replace' , gzip_compress = False ) : ( writer , outf ) = outf_writer_compat ( outfile , encoding , errors , gzip_compress ) writer . writerow ( fields ) for line in fp : tweet = json . loads ( line ) row = extract_fields ( tweet , fields ) writer . writerow ( row ) outf . close ( )
extract selected fields from a file of line-separated json tweets and write to a file in csv format .