zemirco / json2csv

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

Newlines are not created correctly #91

Closed lillem4n closed 7 years ago

lillem4n commented 8 years ago

Instead of a newline in a field, I just get the string \n .

When I manually create the CSV string myself, it works great.

vroudge commented 8 years ago

Same issue.

knownasilya commented 8 years ago

@vroudge can you provide sample JSON data that is affected?

kayheunen commented 8 years ago

{"Subject":"Artis ZOOmeravonden","Start Date":"07/02/2016","Start Time":"03:00 PM","End Date":"07/02/2016","End Time":"10:00 PM","All Day Event":false,"Description":"Artis in the evening\nLetting Amsterdam’s party animals in, ZOOmeravonden welcomes guests to explore the Artis Royal Zoo during the summer evenings until sunset. Some of the animals will be shaking off the last bit of energy before bed, while others will still be wide-eyed and of course those nocturnal animals are just waking up. So come get up close and personal with the furry and feathered kind. Zookeepers and animal carers are on hand throughout the zoo to share the secrets of the creatures.\nLive music and activities\nIf the choir of lion roars and bird chirps aren’t enough, adding to the entertainment are well-known Dutch musicians and students from Amsterdam’s music academy taking to the bandstand to serenade the audience. Guests can also take part in workshops, guided tours and activities for children. Dinner is served with picnics and barbecued delicacies available to eat on the lawn.\nStay in the know\nThe name ZOOmeravonden is a play on words with Zoo and Zomer, the Dutch for summer, while ‘avonden’ means evenings. The Artis Royal Zoo is just east of the city’s centre. For more information visit the Artis Royal Zoo website. Website: http://www.artis.nl","Location":"Natura Artis Magistra, Plantage Kerklaan 38-40, 1018 CZ AMSTERDAM"}

knownasilya commented 8 years ago

@kayheunen what options are you running against that JSON?

kayheunen commented 8 years ago

None, atm. I've tried newLine: "\n", newLine: "\n", newLine: '\n', newLine: '\n' and some others.

knownasilya commented 8 years ago

All of the above are the same.

kayheunen commented 8 years ago

Ah sorry, github didn't accept. take the double backslash and the double and single quotes. newLine: "\n" newLine: "\\n" newLine: '\n' newLine: '\\n'

What do you propose to use, given the input in my first comment?

knownasilya commented 8 years ago

single quotes and double quotes don't make a difference. Will look more into this.

kayheunen commented 8 years ago

So what should I put as options? Given that I'm looking for \n as newline separator

corbanb commented 8 years ago

@knownasilya is it an escaping issue?

dbuentello commented 8 years ago

I think the issue is JSON.stringify escapes \n. PR submitted

knownasilya commented 8 years ago

Released as v3.4.2

jharting commented 7 years ago

This was reverted in https://github.com/zemirco/json2csv/commit/eb0bb6edae298f635dd3e4c1c5afe974b1dc13b2

Is there currently some way to work around this issue? Could this be reopen?

danpe commented 7 years ago

Any news?

knownasilya commented 7 years ago

We probably need an excel flag..

mkopinsky commented 7 years ago

This feature is working for me. At least on Mac (I haven't tested on PC), I need to use a \r rather than \n for Excel to recognize it as a newline within a cell.

What is the plan in terms of when this will be released via npm? I see that this issue is tagged as "needs tests" - I can try to take a crack at that if someone points me in the right direction.

knownasilya commented 7 years ago

@mkopinsky did https://github.com/zemirco/json2csv/pull/171 work for you? If so, I can cut a release today.

mkopinsky commented 7 years ago

Yes. I am working through https://github.com/punkave/albedo, and a SQL query like SELECT 'a\rb' UNION SELECT 'c\rd' is generating a CSV file which opens in Excel with the two data cells with line breaks in them.

mkopinsky commented 7 years ago

Hey @knownasilya can you cut that release? Or, is there any other testing I can do that would help?

knownasilya commented 7 years ago

v3.8.0 has been released

mkopinsky commented 7 years ago

Awesome, thanks!!