Skip to content

TypeError: Cannot convert undefined or null to object #222

Closed
@gdonoso94

Description

@gdonoso94

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

Metadata

Metadata

Assignees

Labels

bugdependenciesPull requests that update a dependency file

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions