A CSV to/from JSON converter
A CSV to/from JSON converter library
InstallationCsv2JsonJS is available on NPM registry
npm install csv2jsonjs Usage
Converting JSON to CSV
const fs = require("fs"); const { convertJsonToCsv } = require("csv2jsonjs"); const jsonContent = fs.readFileSync("myfile.json", "utf-8"); const csv = convertJsonToCsv(jsonContent); console.log(csv);
convertJsonToCsv
throws error when given invalid JSON string.
Converting CSV to JSON Object
const fs = require("fs"); const { convertCsvToHash } = require("csv2jsonjs"); const csvContent = fs.readFileSync("myfile.csv", "utf-8"); const json = convertCsvToHash(csvContent); console.log(json);
convertCsvToHash
throws error when given invalid CSV string.
Converting CSV to JSON Array
const fs = require("fs"); const { convertCsvToJSONList } = require("csv2jsonjs"); const csvContent = fs.readFileSync("myfile.csv", "utf-8"); const json = convertCsvToJSONList(csvContent); console.log(json);
convertCsvToJSONList
throws error when given invalid CSV string.
版权声明:
1、该文章(资料)来源于互联网公开信息,我方只是对该内容做点评,所分享的下载地址为原作者公开地址。2、网站不提供资料下载,如需下载请到原作者页面进行下载。