Skip to content
Advertisement

How to format values using json2csv in javascript?

I’m using json2csv v5.0.6 for a small project and I wanted to format some values using custom formatters so I get a clean CSV file.

However, I can’t seem to make the formatters work. I have one number formatter and one string formatter that are supposed to be called upon parsing. Here’s a sample test file that reproduces this behaviour, with two simple formatters:

JavaScript

According to the documentation, the following should work, but it does not. So I’m probably doing something wrong but I have not been to figure out what.

Advertisement

Answer

You have to use the alpha version : json2csv@6.0.0-alpha.0

The last released version has some issue with formatters : https://github.com/zemirco/json2csv/issues/521 (they are not exported)

And you also have to call your formatters functions

JavaScript
Advertisement