Closed apat183 closed 7 years ago
Confirmed, it only takes one argument. You could implement your own unwind and pass the resulting data to this module.
We also accept pull requests 👍
Thanks for confirmation, since I'm passing results from MongoDB it will be easier to unwind myself and pass through.
@knownasilya and others, I was looking for this exact functionality. If I have this JSON as an example:
var myCars = [
{
"carModel": "BMW",
"price": 15000,
"items": [
{
"name": "airbag",
"color": "white"
}, {
"name": "dashboard",
"color": "black"
},
]
}, {
"carModel": "Porsche",
"price": 30000,
"items": [
{
"name": "dashboard",
"items": [
{
"position": "left",
"color": "black"
}, {
"position": "right",
"color": "gray"
}
]
}
]
}
];
I want to have following output CSV:
"BMW",15000,"airbag","white",,
"BMW",15000,"dashboard","black",,
"Porsche",30000,"dashboard",,"left","black"
"Porsche",30000,"dashboard",,"right"","gray"
I can submit a PR, if everyone agrees with these changes to parameters:
var csv = json2csv({
data: myCars,
fields: ['carModel','price','items.name','items.color','items.items.position','items.items.color'],
unwindPath: ['items','items.items']
});
Hi ended up unwinding in mongodb first then passing the results but would love to have it in json2csv as well but it's up to the moderators to agree on parameters etc.
I simplified a little bit the parameters and created a pull request for that.
More of a questions then issue, does unwindPath option only accept one field?
I've tried to put an array and string array into option but doesn't unwind fields. If I only put one field in then it works. Any idea how you can unwind multiple fields?
Thanks