zemirco / json2csv

Convert json to csv with column titles
http://zemirco.github.io/json2csv
MIT License
2.72k stars 362 forks source link

CSV not breaking lines #558

Closed MorenoMdz closed 2 years ago

MorenoMdz commented 2 years ago
  1. Include the version of json2csv used. V 5.0.6

  2. Include your node version/browser vendor and version. Node 14.17

  3. Include a sample dataset that we can test against. Running it on a list of items shaped like:

    {
    item_url: 'url',
    lead_source: 'site',
    item_notes: 'somewhere',
    company_name: 'some company',
    business_phone: '555-555-5555',
    owner_id: '123'
    },
    ...
  4. Tried to generate the file in many ways, for example a very basic attempt:

    
    const fields = [
    "item_url",
    "lead_source",
    "item_notes",
    "company_name",
    "business_phone",
    "owner_id",
    ]
    const opts = { fields }
    
    const csv = parse(res, opts)
    
    await saveDataToFile(csv, `short-url-list-${new Date().toISOString()}`, true)


5. Include your output/error.
The result ends up being a single line CSV file like here:
![image](https://user-images.githubusercontent.com/29472480/151866793-4ac94e5a-2460-40b6-88d6-a117a8004177.png)

The new line tag is being ignore. I am probably doing some stupid mistake here, any ideas?
juanjoDiaz commented 2 years ago

That's seems to be an issue with whatever you are using to open the CSV.

I just run you example and it produced the new lines correctly. Check that you are using the right line ending (linux vs windows).

MorenoMdz commented 2 years ago

That's seems to be an issue with whatever you are using to open the CSV.

I just run you example and it produced the new lines correctly. Check that you are using the right line ending (linux vs windows).

Got thanks I will try, for the past few times we used it I basically exported a JSON as those were properly formatted for some reason, I will take a look at our CSV reader solution next.