0

CSV:

TableName, RowCount, TableStatus
table1, 10, Y
table2, 21, N
table3, 23, Y
table4, 24, N
table5, 25, Y

Need to convert CSV to JSON in this format:

{
    "table1": {
        "row_count": "10"
    }
},
{
    "table3": {
        "row_count": "23"
    }
},
{
    "table5": {
        "row_count": "25"
    }
}

const csvFilePath='sample.csv'
const csv=require('csvtojson')
csv()
.fromFile(csvFilePath)
.then((jsonObj)=>{
    console.log(jsonObj);
    
})
  1. I am using Node csvtojson NPM
  2. I am able to convert to JSON, but I need the json in the above format out of the box. Is it possible?
  3. And also If "TableStatus" value is "N", it should not add that row in JSON.

Note: I am able to convert to desirable JSON format by iterating the JSON object, but is there any way to convert using this NPM.

Thanks.

hardcode
  • 395
  • 3
  • 19
  • Maybe, given there's a variety of hooks, but it wasn't immediately clear how to omit a line--see if you can use the result transform to skip an input row. – Dave Newton Dec 19 '21 at 18:37
  • okay, I will try result transform for omitting line, Thanks. Please let me know if there is any way to convert to the desired JSON format. – hardcode Dec 19 '21 at 18:46

0 Answers0