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

Fix error when a field is null and flatten is used #274

Merged
merged 1 commit into from
Apr 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions bin/utils/TablePrinter.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ class TablePrinter {
const lines = csv.split(this.opts.eol);

const chars = {
'bottom': '',
'bottom-mid': '',
'bottom-left': '',
'bottom-right': ''
};
'bottom': '',
'bottom-mid': '',
'bottom-left': '',
'bottom-right': ''
};

if (!this._hasWritten) {
this.colWidths = this.getColumnWidths(lines[0]);
if (this.opts.header) {
Expand Down
1 change: 1 addition & 0 deletions lib/JSON2CSVBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ class JSON2CSVBase {
: key;

if (typeof value !== 'object'
|| value === null
|| Array.isArray(value)
|| Object.prototype.toString.call(value.toJSON) === '[object Function]'
|| !Object.keys(value).length) {
Expand Down
4 changes: 2 additions & 2 deletions test/fixtures/csv/flattenToJSON.csv
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
"hello.world","lorem.ipsum.dolor"
"good afternoon","good evening"
"hello.world","lorem.ipsum.dolor","lorem.ipsum.value"
"good afternoon","good evening",
3 changes: 2 additions & 1 deletion test/fixtures/json/flattenToJSON.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ module.exports = {
},
lorem: {
ipsum: {
dolor: 'good evening'
dolor: 'good evening',
value: null
}
}
}