improve json2csv() as a pure javascript function