mrodrig / json-2-csv

Convert JSON to CSV *or* CSV to JSON!
https://mrodrig.github.io/json-2-csv
MIT License
420 stars 58 forks source link

Incorrect parsing of wrapped values #214

Closed pavelhoral closed 2 years ago

pavelhoral commented 2 years ago

Background Information

The issue I'm reporting is with:

I have...

Expected Behavior

Quoted values split across multiple lines should be correctly parsed.

Actual Behavior

The parser behaves incorrectly when the end quote is at the start of a new line.

Data Sample

CSV:

first,second
"hello
",world

This is being parsed as:

[
  {
    "first": "\",world\n"
  }
]

I did try to fix it but the parser makes almost no sense to me so I am creating this issue and going to find another library or write my own parser :). Good luck.

mrodrig commented 2 years ago

Thanks for reporting this @pavelhoral and apologies that it wasn't working as anticipated for your use case. I've confirmed I can reproduce this issue. I suspect it's a bug with the CSV string parser logic where something isn't quite getting stored properly. I should have some time to walk through this closer this coming weekend, so I'll keep you posted as to when I have a fix published on NPM.

mrodrig commented 2 years ago

Thanks again for reporting this @pavelhoral. I'll be pushing version 3.15.1 to NPM shortly which fixes the issue you identified.

symbianm commented 1 year ago

This bug still exists in the latest 4.1.0 version. From this test file I am getting two incomplete rows test.csv

symbianm commented 1 year ago

I have created new issue https://github.com/mrodrig/json-2-csv/issues/240 because of no answer

mrodrig commented 1 year ago

Hi @symbianm. The bug reported in this issue is not still present in 4.1.0. As tested with the latest release, the output for the CSV sample provided with this issue returns the following, which is correct:

[
    {
        "first": "hello\n",
        "second": "world"
    }
]

I will now switch over to #240 to look into the separate issue you're reporting.