Update json2csv.js

Refactored structure