jsontocsv-csvtojson

0.0.5 • Public • Published

JSON-CSV converter

This simple library convert JSON to CSV and CSV to JSON

JSON to CSV

let converter=new JSONtoCSV(jsonObject,";")
converter.convert() //return a promise

In JSONtoCSV the first argument must be an array of JSON objects

CSV to JSON

let converter=new CSVtoJSON(csvString,";")
converter.convert() //return a promise

CSVtoJSON accept as third argument the path of a CSV file

In both JSONtoCSV and CSVtoJSON the second argument is the delimiter for CSV, the default one is , (coma).

Example

const {JSONtoCSV} = require("jsontocsv-csvtojson")
 
let jsonObject=[{
    NAME: "Luke",
    AGE: 20
},
{
    NAME: "Fernando",
    AGE: 41
}]
let converter=new JSONtoCSV(jsonObject,";")
converter.convert()
    .then(csv=>{
        console.log(csv)
        /**
         * csv will be:
         * 
         * NAME;AGE
         * Luke;20
         * Fernando;41
         * 
         * */ 
    })

Package Sidebar

Install

npm i jsontocsv-csvtojson

Weekly Downloads

4

Version

0.0.5

License

MIT

Unpacked Size

6.05 kB

Total Files

4

Last publish

Collaborators

  • corxo