Skip to content
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

When parsing an array of objects, it fails if one object is null #55

Open
captixn opened this issue Feb 20, 2021 · 0 comments
Open

When parsing an array of objects, it fails if one object is null #55

captixn opened this issue Feb 20, 2021 · 0 comments

Comments

@captixn
Copy link

captixn commented Feb 20, 2021

Hi,

When parsing an array of object with:
var xls = json2xls(json)
I stumbled onto this error :

        if (n in object) {
              ^

TypeError: Cannot use 'in' operator to search for 'count' in null
    at getByString (C:\Users\capti\dev\essec_scraper\node_modules\�[4mjson2xls�[24m\lib\json2xls.js:33:15)
    at C:\Users\capti\dev\essec_scraper\node_modules\�[4mjson2xls�[24m\lib\json2xls.js:70:25
    at Array.map (<anonymous>)
    at C:\Users\capti\dev\essec_scraper\node_modules\�[4mjson2xls�[24m\lib\json2xls.js:69:23
    at Array.map (<anonymous>)
    at Function.transform.prepareJson (C:\Users\capti\dev\essec_scraper\node_modules\�[4mjson2xls�[24m\lib\json2xls.js:68:24)
    at transform (C:\Users\capti\dev\essec_scraper\node_modules\�[4mjson2xls�[24m\lib\json2xls.js:4:26)
    at file:///C:/Users/capti/dev/essec_scraper/convertData.js:7:11
�[90m    at ModuleJob.run (internal/modules/esm/module_job.js:152:23)�[39m
�[90m    at async Loader.import (internal/modules/esm/loader.js:166:24)�[39m

It appears function getByString(object, path) does not check for null for "object".
Therefore,

transform.prepareJson = function(json,config) {
....
res.rows = jsonArr.map(function(row) {
        return fields.map(function(key) {
            var value = getByString(row,key);


Will fail.
As a simple fix, I added

    if(object == null){
        return ""
    } 

to function getByString(object, path).
So that the rest of the array can be prepared..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant