0.0.5 • Published 5 years ago
jsontocsv-csvtojson v0.0.5
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
*
* */
})