@ideadesignmedia/json-csv
v1.0.2
Published
All in one JSON to CSV and CSV to JSON package
Downloads
10
Readme
jsoncsv
About
All in one JSON to CSV and CSV to JSON package
Installation
yarn install @ideadesignmedia/json-csv
Usage
const { csv, json, convertFormat } = require('@ideadesignmedia/json-csv')
csv()
csv(JSON, fields) => CSV as String example:
let object = [
{"name": "Sam", "height": "6'2\""},
{"name": "Jim", "height": "7'3\""}
]
let result = csv(object, ['height'])
console.log(result)
/*
"height"
"6'2"""
"7'3"""
*/
json()
json(CSV as String, fields) => JSON Object Returns a promise example:
let string = `"name","height"
"Sam","6'2"""
"Jim","7'3"""`
json(string, ['height']).then(result => {
console.log(result)
/*
[
{"height": "6'2\""},
{"height": "7'3\""}
]
*/
})
###convertFormat()
convertFormat(path, fields) => ConvertedDocument Provide the path to a csv or json file and get the result as the other format example:
let doc = './document.csv'
convertFormat(doc).then(r => {
console.log(r)
/*
document as a json array of objects
*/
})
doc = './document.json'
convertFormat(doc).then(r => {
console.log(r)
/*
CSV string of that json document
*/
})