โ06-07-2018 02:24 PM
I have a need to write an โemptyโ CSV file that includes only the header row information in the case that thereโs no data to populate the file. Does anyone know a good way to do this? Anything to do with the CSV formatter and the header row options doesnโt seem to be working out. Itโs always writing a row of data with blanks for each element separated by the delimiter. Appreciate any thoughts, thanks.
โ06-08-2018 03:38 PM
I donโt think itโs possible to configure the CSV Formatter to do this at the moment. You might need to do something like the following to detect when there is no data:
So, on the โNo Dataโ branch, you can have a Mapper that defines the headers and a CSVFormatter that writes the document to the file. Not great, I wish I had a better answer.
โ06-12-2018 01:19 PM
Thanks tstack. Thatโs what we ended up implementing. Agreed, it is not great, especially for a document with dozens of header columns.
โ09-28-2020 11:33 AM
For others whom happen to search for this as I just did. The router approach is still required as far as I can tell for the โNo Dataโ condition, but, an easier way to write a header only file is to parse your JSON and use a Constant with a File Writer. For example, the following will get a list of Keys from your JSON (headers) as an array, turn it into a string, then, remove the opening and closing brackets.
JSON.stringify(Object.keys($)).replace(โ[โ,โโ).replace(โ]โ,โโ)
You can drop that into a Constant Snap and write to file. Works well for this case.
โ01-08-2021 02:17 PM
Can you share a screenshot of your pipeline that handle this? from the router.
I am in the same situation. I need to write an empty with header CSV file if there is no input data.
Thanks