zemirco / json2csv

Convert json to csv with column titles
http://zemirco.github.io/json2csv
MIT License
2.72k stars 362 forks source link

How can I modify my data before converting to CSV? #363

Closed arunkumarreddygoluguri closed 5 years ago

arunkumarreddygoluguri commented 5 years ago

How to change the value of a particular column and then convert to csv, for example json object has timestamp i want to convert it into proper datetime and then convert to csv and also how to add index as the first column

juanjoDiaz commented 5 years ago

Preprocessing! This library is meant to conver from json to csv, not to manipulate your data.

const data = [
  { timestamp: 1553102860253 }
];

const preprocessedData = data.map((item, i) => ({ index: i, timestamp: new Date(item.timestamp) }));
const csv = json2csv.parse(preprocessedData);
arunkumarreddygoluguri commented 5 years ago

@juanjoDiaz Thanks for the update