mrodrig / json-2-csv

Convert JSON to CSV *or* CSV to JSON!
https://mrodrig.github.io/json-2-csv
MIT License
421 stars 58 forks source link

TypeError: Cannot convert undefined or null to object #222

Closed gdonoso94 closed 1 year ago

gdonoso94 commented 2 years ago

Background Information

The issue I'm reporting is with:

I have...

Hi, I've been trying to convert from a pretty nested and unstructured json file to a csv using this package and the expandArrayObjects: true option, but looks like it is unable to convert some objects in my data. This is pretty much the stack trace the server is throwing:

[1] TypeError: Cannot convert undefined or null to object
[1]     at Function.keys (<anonymous>)
[1]     at generateDeepKeysList (/repos/XXXX/node_modules/deeks/lib/deeks.js:42:23)
[1]     at deepKeys (/repos/XXXX/node_modules/deeks/lib/deeks.js:19:16)
[1]     at /repos/XXXX/node_modules/deeks/lib/deeks.js:35:20
[1]     at Array.map (<anonymous>)
[1]     at deepKeysFromList (/repos/XXXX/node_modules/deeks/lib/deeks.js:32:17)
[1]     at processArrayKeys (/repos/XXXX/node_modules/deeks/lib/deeks.js:71:24)
[1]     at /repos/XXXX/node_modules/deeks/lib/deeks.js:51:20
[1]     at Array.map (<anonymous>)
[1]     at generateDeepKeysList (/repos/XXXX/node_modules/deeks/lib/deeks.js:42:34)

Is there any workaround to do this? I've tried sanitizing the main keys, i.e. removing the first level keys with null|undefined value. But it looks like the problem is in a deeper level.

I wish I could share some data to test but I can't.

Thanks in advance

mrodrig commented 1 year ago

Thanks for your patience on this @gdonoso94. I just pushed a patch for this in the underlying deeks module that should resolve the issue. I'll be pushing out a new version of json-2-csv which updates to the patched version shortly as 3.18.0. Please let me know if you still run into the issue with that version. Thanks!