0

I have the following string and would like to convert it to json in javascript/node.js.

Issues:

  1. It has \r\n not just \n
  2. There are , in the fields, for example in the description
  3. There are " which need to be removed but also could be in the description.

Perhaps there is a better way to process the multer.buffer than toString() ?

"name,description\r\nParis,The home of the eiffel tower\r\nMadrid,Madrid is home to two world-famous football clubs, Real Madrid and Atletico Madrid\r\n"

Prefered Output:

[
    {
        "name": "Florida beach getaway",
        "description": "Soft beach sands, warm sunsets, calm waters"
    },
    {
        "name": "Iceland",
        "description": "Explore the dramatic landscape with volcanoes, geysers, hot springs and lava fields"
    }
]

I have tried csv-parse and papa-parse and neither are able to handle this line,

Madrid is home to two world-famous football clubs, Real Madrid and Atletico Madrid
eol
  • 23,236
  • 5
  • 46
  • 64
Terry
  • 1,621
  • 4
  • 25
  • 45

0 Answers0