express-csv icon indicating copy to clipboard operation
express-csv copied to clipboard

Error exporting object data

Open CoinCoderBuffalo opened this issue 11 years ago • 1 comments

Getting a strange output in the Excel CSV file:

[object Object]|"false"||"0"|"[object Object]"|"[object Object]"|"[object Object]"|"function () { var self = this , hookArgs // arguments eventually passed to the hook - are mutable , lastArg = arguments[arguments.length-1] , pres = this._pres[name] , posts = this.posts[name] , total = pres.length , current = -1 , asyncsLeft = proto[name].numAsyncPres , next = function () { if (arguments[0] instanceof Error) { return handleError(arguments[0]); } var args = Array.prototype.slice.call(arguments) , currPre , preArgs; if (args.length && !(arguments[0] == null && typeof lastArg === 'function')) hookArgs = args; if (++current < total) { currPre = pres[current] if (currPre.isAsync && currPre.length < 2) throw new Error(""Your pre must have next and done arguments -- e.g., function (next, done, ...)""); if (currPre.length < 1) throw new Error(""Your pre must have a next argument -- e.g., function (next, ...)""); preArgs = (currPre.isAsync ? [once(next), once(asyncsDone)] : [once(next)]).concat(hookArgs); return currPre.apply(self, preArgs); } else if (!proto[name].numAsyncPres) { return done.apply(self, hookArgs); } } , done = function () { var args = Array.prototype.slice.call(arguments) , ret, total, current, next, done, postArgs; if (current === total) { ret = fn.apply(self, args); total = posts.length; current = -1; next = function () { if (arguments[0] instanceof Error) { return handleError(arguments[0]); } var args = Array.prototype.slice.call(arguments, 1) , currPost , postArgs; if (args.length) hookArgs = args; if (++current < total) { currPost = posts[current] if (currPost.length < 1) throw new Error(""Your post must have a next argument -- e.g., function (next, ...)""); postArgs = [once(next)].concat(hookArgs); return currPost.apply(self, postArgs); } }; if (total) return next(); return ret; } }; if (_asyncsLeft) { function _asyncsDone (err) { if (err && err instanceof Error) { return handleError(err); } --_asyncsLeft || _done.apply(self, hookArgs); } } function handleError (err) { if ('function' == typeof lastArg) return lastArg(err); if (errorCb) return errorCb.call(self, err); throw err; } return _next.apply(this, arguments); }"|"[object Object]"

CoinCoderBuffalo avatar May 28 '13 20:05 CoinCoderBuffalo

I did a workaround by first converting the data to JSON and then converting it back to Object.

Added one line to the code, and made sure to send it JSON data. I think the original issue was a bunch of "meta" properties were set that obj.hasOwnProperty(prop) was not filtering out.

res.csv = function(obj, headers, status) { obj = JSON.parse(obj);

CoinCoderBuffalo avatar May 28 '13 21:05 CoinCoderBuffalo