-
Notifications
You must be signed in to change notification settings - Fork 58
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
Problem with list of objects same keys #207
Comments
Thanks for reporting this @mebibou. I can definitely see this as being useful as well, especially if converting back to JSON from CSV is a requirement. I'll take a look at how I could make this work with the existing |
Tank You guys. Congulations! |
I just ran into this issue as well. It would be great to have! :D |
Same requirement, it would be useful feature to me |
Added to work on support for use case described in mrodrig/json-2-csv#207
Add arrayIndexesAsKeys option for #207
Thanks to everyone demonstrating support for this use case and issue. I just released version Here's an example: const { json2csv } = require('json-2-csv');
const data = [
{
test: {
list: [{
a: 1,
optionA: 'ac'
}, {
a: 2,
optionB: 'radio'
}]
},
},
{
test: {
list: [{
a: 3,
optionA: 'cd'
}, {
a: 4,
optionB: 'heat'
}]
}
}
];
const options = { arrayIndexesAsKeys: true, expandArrayObjects: true };
const csv = json2csv(data, options)
console.log(csv); which outputs the following CSV:
|
Hi, Thank you for the great work here @mrodrig. Looking at this I can see some issues which may not have been accounted for. Is this supported in CLI? Does it work the other way round when converting csv to json? like a csv with key test.list.0 would it be interpreted as an array as well? This does not seem to be the case on the CLI. I really need to be able to consistently convert from csv to json and reverse without any issue. So just like this arrays indexes will be used as keys and in converting csv2json the same will be interpreted back to array. |
Background Information
3.14.4
12.22.6
The issue I'm reporting is with:
I have...
When doing the following:
The current resulting csv is:
which looks like you had instead:
But the CSV could actually reflect the original structure if it was like this instead:
I understand some might want the first result, but it would be nice to have an option to have a more like-to-like representation?
The text was updated successfully, but these errors were encountered: