How to convert JSON to CSV format and store in a variable

前端 未结 16 2310
一整个雨季
一整个雨季 2020-11-22 17:31

I have a link that opens up JSON data in the browser, but unfortunately I have no clue how to read it. Is there a way to convert this data using JavaScript in CSV format and

16条回答
  •  旧时难觅i
    2020-11-22 17:59

    There are multiple options available to reuse the existing powerful libraries that are standards based.

    If you happen to use D3 in your project, then you can simply invoke:

        d3.csv.format or d3.csv.formatRows functions to convert an array of objects into csv string.

        d3.csv.formatRows gives you greater control over which properties are converted to csv.

        Please refer to d3.csv.format and d3.csv.formatRows wiki pages.

    There are other libraries available too like jquery-csv, PapaParse. Papa Parse has no dependencies - not even jQuery.

    For jquery based plugins, please check this.

提交回复
热议问题