Custom CSV Headers

Context: the data I want to export to a csv has attributes, that are named for internal use. So in the headers different Strings should be displayed.
When using the CSV: Encode Node object keys that are not part of the headers will be excluded.
CSV: Encode Node | Losant Documentation
It seems to me that I need to decide (when using the CSV: Encode Node) if I either want to have the complete data or the desired headers.

Example
Attributes : [“fruitWeight”, “fruitColor”, “price”]
Desired Headers : [“Fruit Weight”, “Fruit Color”, “Price”]

Is there a smart way to accomplish custom headers (that are different than the object keys)?

Our recommendation would be to use the Function Node to replace the object keys before encoding

There are several different ways to go about it. I’ll work on an example and get back to this thread shortly.

To follow up on this, I’ve attached a workflow file that gives a very basic example of using the Function node to replace object keys.

Given an array (data.fruitData) with object keys [“fruitColor”, “fruitPrice”, “fruitWeight”], we use this in the Function node:

payload.data.fruitDataNew = payload.data.fruitData.map((v) => {
  return {
    'Fruit Color': v.fruitColor,
    'Fruit Price': v.fruitPrice,
    'Fruit Weight': v.fruitWeight
  };
})

This will obviously need to be built upon for your use-case, but please let us know if this helps get you to where you need to be.

fruit-data-csv-develop.flow (2.5 KB)