Skip to content

TypeError: Cannot convert undefined or null to object #222

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

Closed
4 of 5 tasks
gdonoso94 opened this issue Jun 18, 2022 · 1 comment
Closed
4 of 5 tasks

TypeError: Cannot convert undefined or null to object #222

gdonoso94 opened this issue Jun 18, 2022 · 1 comment
Assignees
Labels
bug dependencies Pull requests that update a dependency file

Comments

@gdonoso94
Copy link

Background Information

  • Module Version: latest
  • Node/Browser Version: 18.1.0

The issue I'm reporting is with:

  • json2csv
  • csv2json

I have...

  • searched to see if an issue has already been reported.
  • verified that my JSON/CSV data is valid (using something like http://jsonlint.com or https://csvlint.io/).
  • tried upgrading to the latest version of json-2-csv (since the issue may already be fixed).

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 added a commit to mrodrig/deeks that referenced this issue Nov 22, 2022
Initially reported in mrodrig/json-2-csv#222
This issue appears when a `null` value is passed for key enumeration because technically `null` is an object, but doesn't have keys. This commit fixes the issue by adding a null check to prevent the type error.
@mrodrig mrodrig self-assigned this Nov 22, 2022
@mrodrig mrodrig added bug dependencies Pull requests that update a dependency file labels Nov 22, 2022
mrodrig added a commit to mrodrig/deeks that referenced this issue Nov 22, 2022
* fix: resolve "TypeError: Cannot convert undefined or null to object"

Initially reported in mrodrig/json-2-csv#222
This issue appears when a `null` value is passed for key enumeration because technically `null` is an object, but doesn't have keys. This commit fixes the issue by adding a null check to prevent the type error.

* chore(deps): npm audit fix

* chore(rel): 2.6.0
@mrodrig mrodrig mentioned this issue Nov 22, 2022
@mrodrig
Copy link
Owner

mrodrig commented Nov 22, 2022

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug dependencies Pull requests that update a dependency file
Projects
None yet
Development

No branches or pull requests

2 participants