Search code examples
javascriptpapaparse

Replacing empty Strings with custom text (PapaParse)


Is there a way PapaParse can replace empty Strings to a custom text? I want to export JSON to CSV but when there is a field with no data in it I want to export something like "MISSING DATA" automatically without going trough my array with a loop checking if there is data

those are my options:

this.csvFile = this.papa.unparse(jsonData,this.options);


  options = {
  quotes: false, //or array of booleans
  quoteChar: '""',
  delimiter: ";",
  header: false,
  skipEmptyLines: true,

}


Solution

  • You can use option transform it should be a function that receives a field value as an argument and based on this value you can modify it.

    Here are the docs: https://www.papaparse.com/docs#json-to-csv

    transform - A function to apply on each value. The function receives the value as its first argument and the column number or header name when enabled as its second argument. The return value of the function will replace the value it received. The transform function is applied before dynamicTyping.