`I have a MR that reads a CSV file and creates a j...
# suitescript
i
I have a MR that reads a CSV file and creates a json object, Im using eric, solution
Copy code
csvFile.lines.iterator().each((line) => {
      const w = line.value.split(',');
      const obj = {};
      log.audit({ title: 'line', details: line });
      log.audit({ title: 'line.value', details: line.value });
      log.audit({ title: 'w', details: w });

      if (headerCounter === 0) {
        w.forEach((header) => headers.push(header));
        headerCounter += 1;
      } else {
        w.forEach((el) => {
          const headerName = headers[dataCounter];

          if (!obj[headerName]) {
            obj[headerName] = el;
          }

          dataCounter += 1;
        });
        fileData.push(obj);
      }
      return true;
    });
The problem is that the object is being created like this
Copy code
{
      "'import_profile'": "'BBL_TT'",
      " 'itemid'": " '24152'",
      " 'upccode'": " '840154708304'",
   }
With double quotes, the csv has data like this
Copy code
'itemid', 'upccode'
'123', '456'
Should I be creating the csv without quotes? How do I handle a multiple select option for a field, I was doing something like this
Copy code
'[1,2,3]'
But this separates the three values as Im separating by comma on the function.
the csv rfc is pretty short
but basically there is an escape mechanism for csv control characters
anything that ends up using them ends up adding a lot of complexity to a csv parser
for example, you can't split on commas anymore
i
thanks @battk! As always teaching me stuff I should already know u.u hahaha