Closed decaller closed 4 years ago
@decaller Should be fixed with https://github.com/kauegimenes/jsonexport/commit/7270f4873ba8e7fa87027ce52546c08122d7aaef
@decaller In v2.0.0 you can use fillGaps
option to get this behavior.
thank you for the update, really appreciate it
Hi, I use similar kind of multi-array set. I am using the below input:
var test=[{
"CODE": "AA",
"GROUP_NAME": "aaaaaa",
"GROUP_DESC": "aaaaaaaaa",
"CHILD_GROUP": [{
"CODE": "AA",
"GROUP_NAME": "aaaaaa",
"CHILD_CODE": "bb"
},
{
"CODE": "AA",
"GROUP_NAME": "aaaaaa",
"CHILD_CODE": "cc"
},
{
"CODE": "AA",
"GROUP_NAME": "aaaaaa",
"CHILD_CODE": "dd"
}
]
}]
jsonexport(test,function(err, csv){
if(err) return console.log(err);
console.log(csv);
});
And my output is :
CODE,GROUP_NAME,GROUP_DESC,CHILD_GROUP.CODE,CHILD_GROUP.GROUP_NAME,CHILD_GROUP.CHILD_CODE AA,aaaaaa,aaaaaaaaa,AA,aaaaaa,bb ,,,AA,aaaaaa,cc ,,,AA,aaaaaa,dd
The first child is getting appended to the parent. Could you please provide a solution for this???
I need the output like this: AA,aaaaaa,aaaaaaaaa ,,,AA,aaaaaa,bb ,,,AA,aaaaaa,cc ,,,AA,aaaaaa,dd
I abolsutely think this issue should be closed.
@saipallavi, I have starred your example over for quite sometime. I disagree with you, I see expected result. A child-arrary's first row belongs with-in the parent row. If jsonexport did what you are asking for, it'd be a hard breaking change. Your "I need the output like this" example, would actually mean you have a 2nd parent who's CODE, GROUP_NAME, and GROUP_DESC are all null but has a 3 child length array (not to mention row 1 has no children).
Lets close this. Wouldn't even offer an option to pivot the behavior to keep tight format standards
@AckerApple I think there is a way we can provide this behavior without breaking changes.
If we add a new option handleArray(array)
that allows the user to change the array like the other handle functions.
To do this we could add this call
array = self._options.handleArray(array);
At: https://github.com/kauegimenes/jsonexport/blob/master/lib/parser/handler.js#L100
var jsonexport = require('jsonexport');
var data = [{
"CODE": "AA",
"GROUP_NAME": "aaaaaa",
"GROUP_DESC": "aaaaaaaaa",
"CHILD_GROUP": [{
"CODE": "AA",
"GROUP_NAME": "aaaaaa",
"CHILD_CODE": "bb"
},
{
"CODE": "AA",
"GROUP_NAME": "aaaaaa",
"CHILD_CODE": "cc"
},
{
"CODE": "AA",
"GROUP_NAME": "aaaaaa",
"CHILD_CODE": "dd"
}
]
}];
var options = {
handleArray: function(array){
return [{CODE: " ", GROUP_NAME: " ", CHILD_CODE: " "}].concat(array);
}
};
jsonexport(data, options, function(err, csv){
if(err) return console.log(err);
console.log(csv);
});
What you think about this @AckerApple and @saipallavi ?
My thought is that it will get awfully ugly and convoluted for arrays inside arrays, or array of objects with arrays.
I wouldn't approach this one as a catering company. Don't do, a change like this needs an accompanying document type. CSV doesn't have metadata by nature. You best stick to as little format variations as possible.
We can do anything, don't think we should for consistency sake
@saipallavi should be fixed in 3.0.0
after https://github.com/kauegimenes/jsonexport/pull/68 gets merged
@saipallavi jsonexport@3.0.0
got released, feel free to reopen this issue if you still get the incorrect output.
Here's my code
and here is the output
as you can see, the values are not supposed to be there. It should drop on the next line. And is there any option to force rewrite values so it would be look like this?
Thank you..