Write output to json and csv files