zemirco / json2csv

Convert json to csv with column titles

Home Page:http://zemirco.github.io/json2csv

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error in unwinding empty array

documanish opened this issue · comments

Unwinding an empty array is emitting empty csv. Below is a sample code to reproduce the issue

const { Parser, transforms: { unwind } } = require('json2csv');
const myCars = [
  {
    "carModel": "Audi",
    "price": 0,
    "segments":[{
        "colors": ["blue"],
        "empty": []
        }
    ]
      }
];
const fields = ['carModel', 'price','segments', 'segments.colors', 'segments.empty'];
const transforms = [unwind({ paths: ['segments', 'segments.colors', 'segments.empty'], blankOut: true })];
const json2csvParser = new Parser({ fields, transforms });
const csv = json2csvParser.parse(myCars);
console.log(csv);

Output:
"\"carModel\",\"price\",\"segments\",\"segments.colors\",\"segments.empty\""

This look like a bug indeed.
I'll look into it!

Hello @zemirco and @juanjoDiaz!
I have spotted the same issue with the latest stable version 5.0.6. Also, I have noted that some similar issue(#497) was opened and even fixed(3b74735) a long time ago(in 2020). The current issue is not labeled to any fix or something like that.

What is the current status of it? Are you going to fix this in version 6 or backport this to the current? I can dive into it and try to fix it, but I need to know your expectations.

Hi, i have the same issue and it seems that it has a fix however whenever i tried to npm install -g json2csv, the files were not updated. I am not sure how to update the files.

Thanks for pointing this out, looks like we need to do a new release. Will try to do it this week