Skip to content
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

unwindPath only accepts one field #174

Closed
apat183 opened this issue May 23, 2017 · 5 comments
Closed

unwindPath only accepts one field #174

apat183 opened this issue May 23, 2017 · 5 comments

Comments

@apat183
Copy link

apat183 commented May 23, 2017

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

@knownasilya
Copy link
Collaborator

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 👍

@apat183
Copy link
Author

apat183 commented May 23, 2017

Thanks for confirmation, since I'm passing results from MongoDB it will be easier to unwind myself and pass through.

@eduardomourar
Copy link
Contributor

eduardomourar commented Jul 3, 2017

@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']
});

@apat183
Copy link
Author

apat183 commented Jul 6, 2017

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.

@eduardomourar
Copy link
Contributor

I simplified a little bit the parameters and created a pull request for that.

knownasilya pushed a commit that referenced this issue Jul 10, 2017
* Add unwind multiple times as array

* Change small details as requested
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants