Skip to content

CSV to JSON is incorrectly tranformed if there is a field that starts with a break line. #265

Closed
@AndrzejKmicic

Description

@AndrzejKmicic

Background Information

  • Module Version:
  • Node/Browser Version:

The issue I'm reporting is with:

  • json2csv
  • csv2json

I have...

  • searched to see if an issue has already been reported.
  • verified that my JSON/CSV data is valid (using something like http://jsonlint.com or https://csvlint.io/).
  • tried upgrading to the latest version of json-2-csv (since the issue may already be fixed).

Expected Behavior

CSV to JSON is correctly tranformed if there is a field that starts with a break line.

{"id":1,"name":"John Doe","age":29,"city":"New York"}
{"id":2,"name":"Jane Smith","age":34,"city":"\n Los Angeles"}
{"id":3,"name":"Emily Davis","age":22,"city":"Chicago"}
{"id":4,"name":"Michael Brown","age":40,"city":"Houston"}

Actual Behavior

CSV to JSON is incorrectly tranformed if there is a field that starts with a break line.

{"id":1,"name":"John Doe","age":29,"city":"New York"}
{"id":2,"name":"Jane Smith","age":"34,\""}
{"id":" Los Angeles\""}
{"id":3,"name":"Emily Davis","age":22,"city":"Chicago"}
{"id":4,"name":"Michael Brown","age":40,"city":"Houston"}

Data Sample

CSV:

id,name,age,city\n1,John Doe,29,New York\n2,Jane Smith,34,"\n Los Angeles"\n3,Emily Davis,22,Chicago\n4,Michael Brown,40,Houston

Code Example

Stackblitz

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions