Search code examples
javascriptpapaparse

In Papaparser, How to handle multiple values?


I have a csv like this:

name, email
raja, "[email protected], [email protected]"

Note that email has two values.

I want my json to be like:

{
   "name": "raja"
    "email": ["[email protected]","[email protected]"]
}

Is there any way to do it in papa parser ?


Solution

  • The parser cannot handle your email array format, try to change to something like:

    name,email
    raja,[email protected]|[email protected]
    

    Inside config object do this:

    var config = {
        //... other config settings
        complete: function (parsed) {
            parsed.data.forEach(row => Object.assign(row, {email: row.email.split("|")}))
        }
    };