Skip to content

potential bug: empty value in input where 0 expected #4

@kurttheviking

Description

@kurttheviking

I am not sure if this is expected behavior or a bug, so I am submitting it for further consideration. Any guidance is much appreciated!

Setup

Running node 0.10.26, json-2-csv 0.1.4:

var converter = require('json-2-csv');

var data = [
  {
    label: 'first',
    value: 10
  },
  {
    label: 'second',
    value: 0
  },
  {
    label: 'third',
    value: 20
  }
];

converter.json2csv(data, function (err, csv) {
  console.log(csv);
});

Observed

label,value
first,10
second,
third,20

Expected

label,value
first,10
second,0
third,20

Note that the expected output contains a 0 on the line associated with the label second as provided in the input data.

Cause?

This appears to be caused by a value || '' check and 0 evaluates to falsy.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions