Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Newlines are not created correctly #91

Closed
lillem4n opened this issue Dec 8, 2015 · 21 comments
Closed

Newlines are not created correctly #91

lillem4n opened this issue Dec 8, 2015 · 21 comments
Assignees

Comments

@lillem4n
Copy link

lillem4n commented Dec 8, 2015

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

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

@knownasilya knownasilya changed the title Newliens are not created correctly Newlines are not created correctly Jan 3, 2016
@vroudge
Copy link

vroudge commented Jan 25, 2016

Same issue.

@knownasilya
Copy link
Collaborator

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

@kayheunen
Copy link

{"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
Copy link
Collaborator

@kayheunen what options are you running against that JSON?

@kayheunen
Copy link

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

@knownasilya
Copy link
Collaborator

All of the above are the same.

@kayheunen
Copy link

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
Copy link
Collaborator

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

@kayheunen
Copy link

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

@knownasilya knownasilya self-assigned this Apr 4, 2016
@corbanb
Copy link

corbanb commented May 19, 2016

@knownasilya is it an escaping issue?

@dbuentello
Copy link
Contributor

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

@knownasilya
Copy link
Collaborator

Released as v3.4.2

@jharting
Copy link

jharting commented Oct 4, 2016

This was reverted in eb0bb6e

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

@danpe
Copy link

danpe commented Jan 31, 2017

Any news?

@knownasilya
Copy link
Collaborator

We probably need an excel flag..

glutentag pushed a commit to glutentag/json2csv that referenced this issue Apr 25, 2017
\n and \r are converted to \u2028 and \u2029 in order to pass through
JSON.stringify, then converted back to \n and \r.
Note any original \u2028 and \u2029 are converted to \n and \r.
glutentag pushed a commit to glutentag/json2csv that referenced this issue Apr 25, 2017
\n and \r are converted to \u2028 and \u2029 in order to pass through
JSON.stringify, then converted back to \n and \r.
Note any original \u2028 and \u2029 are converted to \n and \r.
glutentag pushed a commit to glutentag/json2csv that referenced this issue Apr 25, 2017
…rco#91)

\n and \r are converted to \u2028 and \u2029 in order to pass through
JSON.stringify, then converted back to \n and \r.
Note any original \u2028 and \u2029 are converted to \n and \r.
knownasilya pushed a commit that referenced this issue May 8, 2017
…#91) (#171)

* Preserve new lines in cells with option preserveNewLinesInCells (#91)

\n and \r are converted to \u2028 and \u2029 in order to pass through
JSON.stringify, then converted back to \n and \r.
Note any original \u2028 and \u2029 are converted to \n and \r.

* fixup! Preserve new lines in cells with option preserveNewLinesInCells (#91)
@mkopinsky
Copy link
Contributor

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
Copy link
Collaborator

@mkopinsky did #171 work for you? If so, I can cut a release today.

@mkopinsky
Copy link
Contributor

mkopinsky commented Jun 13, 2017

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
Copy link
Contributor

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

@knownasilya
Copy link
Collaborator

v3.8.0 has been released

@mkopinsky
Copy link
Contributor

Awesome, thanks!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants