-
Notifications
You must be signed in to change notification settings - Fork 57
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
Empty Array Being Returned as Header causing JSON to be Outputted in CSV #168
Comments
To note, while messing around I found a way to get the expected output, but do not think it is the correct solution as it causes a test to fail. I solved it by updating } else if (isArrayToRecurOn(data[currentKey]) && !data[currentKey].length) {
return []
} and then changing
This is obviously not the right solution, however it brings about the expected output and may help you find the correct solution. |
In order to convert the generated CSV back to the most accurate JSON possible, the module must still insert `[]` for unwound empty array values. However, there are some legitimate cases where users want to be able to have the module ignore these values so that the generated CSV is a bit more user-friendly, depending on the data being converted. This new option allows users the ability to achieve this without impacting existing use cases, as the user has opted to specify an option which may impact the ability to convert the CSV back to JSON later on. Fixes #168
In order to convert the generated CSV back to the most accurate JSON possible, the module must still insert `[]` for unwound empty array values. However, there are some legitimate cases where users want to be able to have the module ignore these values so that the generated CSV is a bit more user-friendly, depending on the data being converted. This new option allows users the ability to achieve this without impacting existing use cases, as the user has opted to specify an option which may impact the ability to convert the CSV back to JSON later on. Fixes #168
I'm having a similar issue, but with Objects. E.g.:
result:
I've looked through the docs to see how I might address this, but I've come up with nothing... Any tips? 🙏 |
@loganpowell I switched to https://github.com/kaue/jsonexport but I recommend using my fork from this PR: kaue/jsonexport#90 |
@hdwatts I tried that, but that leaves something to be desired as well. I'll follow up on that PR. with more info |
I've used a work around to make sure a null set is present to keep the object structures similar and that is working for me atm... e.g.: const test_json = [
{
a: 1,
b: 2,
c: {
ca: 1,
cb: 2,
},
},
{
a: 3,
b: 4,
c: {},
},
]
const xfd = test_json.reduce((acc, cur) => {
const null_set = { ca: null, cb: null }
const { c, ...rest } = cur
return acc.push({ ...((c.ca && { c }) || { c: null_set }), ...rest }), acc
}, [])
json2csvAsync(xfd).then(console.log) //? result:
|
Hit the same issue as @loganpowell with an empty object yielding an unwanted JSON-filled column. Used a similar workaround. |
Thanks for bringing this up again. I'm trying to make some progress on these issues and will take another look to see if I can find a solution to resolve this since I agree that the behavior of printing a JSON object's representation isn't ideal. |
It happens the same to me |
Background Information
3.7.8
86.0.4240.80
The issue I'm reporting is with:
I have...
Expected Behavior
Actual Behavior
Data Sample
JSON:
Code Example
The text was updated successfully, but these errors were encountered: