Closed Bakabake closed 4 years ago
Thanks for reporting this @Bakabake. Another good find. I have a PR out to handle that scenario and will merge it in once the tests finish running. I should have it published to NPM in a little bit as 3.7.5
. Thanks again for reporting it and for all of the additional notes you provided. They were really helpful.
Anytime! I'm always happy to help!
Hi @mrodrig
I am facing a similar issue to this.
Input: sender_id,receiver_id,message,image\r\nu1,"u2","m1",\r\nu1,"u3","m2",
Expected Output:
[
{ sender_id: 'u1', receiver_id: 'u2', message: 'm1', image: '' },
{ sender_id: 'u1', receiver_id: 'u3', message: 'm2', image: '' },
]
Actual Output:
[
{ sender_id: 'u1', receiver_id: 'u2', message: 'm1', image: '' },
{ sender_id: 'u1', receiver_id: 'u3', message: 'm2', image: ',' },
]
Code:
const parsed = csvParser.csv2json(data, {
trimFieldValues: true,
trimHeaderFields: true,
});
So the issue occurs when at the end of nth row, there is no line break(lf or crlf), and the (m-1)st column has quoted string.
Please let me know if you require a minimum reproduction code. I will create a separate issue then.
Background Information
3.7.4
10.16.0
The issue I'm reporting is with:
I have...
Expected Behavior
If there exists an empty element as the very last entry of the CSV, an empty value should be written out.
Actual Behavior
The last field does not get written out, and the previous element has a comma appended to the end of the value. Using the csv/code below, the output will be:
Data Sample
CSV:
Code Example
Additional Notes
I've noticed that consecutive empty values also cause the same issue.
Use the above test code with the following csv:
The resulting JSON will look like:
Multiple empty rows produce proper output except for the last row:
Results in:
Also, if the last element is not empty, everything works fine. Using this csv:
Produces the appropriate JSON: