-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Wrong placement in multi-array set #22
Comments
@decaller In v2.0.0 you can use |
thank you for the update, really appreciate it |
Hi, 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 The first child is getting appended to the parent. Could you please provide a solution for this??? I need the output like this: |
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. 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 Usage examplevar 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 |
@saipallavi |
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..
The text was updated successfully, but these errors were encountered: