#!/usr/bin/env python #Convert json array file in csv file #import import ijson import csv import time import sys import os import datetime os.chdir('/home/julien_ha/data') #Start timer start_time = time.time() input_file = sys.argv[1] output_file = input_file.replace('.json','.csv') #Parse json file f1 = open(input_file) d1 = [] for item in ijson.items(f1, "item"): d1.append(item) f = csv.writer(open(output_file, "wb+")) # Write CSV Header, If you dont need that, remove this line f.writerow(["blockHash","blockNumber","from","gas","gasPrice","hash","input","nonce","timestamp","to","transactionIndex","value"]) for t in d1: f.writerow([t["blockHash"], t["blockNumber"], t["from"], t["gas"], t["gasPrice"], t["hash"], t["input"], t["nonce"], t["timestamp"], t["to"], t["transactionIndex"], t["value"] ]) #Print time duration print("Done in --- %s seconds ---" % (time.time() - start_time))