___ _________ __________ _____ ___
/\ \ /\ _____\ /\ ____ \ /\ \ /\ \
\ \ \ \ \ \____/ \ \ \__/\ \ \ \ \ \ \ \ \
\ \ \ \ \ \_______ \ \ \ \ \ \ \ \ \\ \\ \ \
__ \ \ \ \ \_______ \ \ \ \ \ \ \ \ \ \ \ \ \ \
/\ \ \ \ \ \/______/\ \ \ \ \ \ \ \ \ \ \\ \ \\ \
\ \ \_\_\ \ ____\_\ \ \ \ \_\_\ \ \ \ \ \ \ \ \
\ \_________\ /\_________\ \ \_________\ \ \__\ \ \____\
\/_________/ \/_________/ \/_________/ \/__/ \/____/
____________ __________
/\____ ____\ /\ ____ \
\/___/\ \___/ \ \ \__/\ \
\ \ \ \ \ \ \ \ \
\ \ \ \ \ \ \ \ \
\ \ \ \ \ \ \ \ \
\ \ \ \ \ \_\_\ \
\ \__\ \ \_________\
\/__/ \/_________/
_________ _________ ___ ___
/\ _____\ /\ _____\ /\ \ /\ \
\ \ \____/ \ \ \____/ \ \ \ \ \ \
\ \ \ \ \ \_______ \ \ \ \ \ \
\ \ \ \ \_______ \ \ \ \ \ \ \
\ \ \ \/______/\ \ \ \ \ \/ /
\ \ \______ ____\_\ \ \ \ \/ /
\ \________\ /\_________\ \ \____/
\/________/ \/_________/ \/___/
It is a npm package with a function which receives a JSON
object as a parameter and returns a CSV
data to show in tabular form.
✅ Custom key separator 💥
✅ Custom text delimiter and text separator 💥
npm install convert-json-into-csv --save
- JSON object [Object:Required] :- a JSON object which you want to convert to csv.
- Key Separator [String:Optional] :- a symbol to separate the JSON key names of parent and child object. Default value is
_
. - Delimeter [String:Optional] :- a symbol to wrap the CSV value. Default value is
"
. - Value Separator [String:Optional] :- a symbol to separate the diffent values of CSV. Default value is
,
.
import JsonToCsv from 'convert-json-into-csv'; //ES6
//OR
const JsonToCsv = require('convert-json-into-csv'); //ES5
let csv = ``;
let json = {
name: 'Saimon Thada Magar',
company: 'ChicMic, Mohali, India',
profession: 'Software Engineer',
address: {
city: 'Khoptar -4, Rampur',
country: 'Nepal'
}
}
csv = JsonToCsv(json);
console.log(csv);
"name","company","profession","address_city","address_country"
"Saimon Thada Magar","ChicMic, Mohali, India","Software Engineer","Khoptar -4, Rampur","Nepal"
name | company | profession | address_city | address_country |
---|---|---|---|---|
Saimon Thada Magar | ChicMic, Mohali, India | Software Engineer | Khoptar -4, Rampur | Nepal |
import JsonToCsv from 'convert-json-into-csv'; //ES6
//OR
const JsonToCsv = require('convert-json-into-csv'); //ES5
let csv = ``;
let json = {
name: 'Saimon Thada Magar',
company: 'ChicMic, Mohali, India',
profession: 'Software Engineer',
address: {
city: 'Khoptar -4, Rampur',
country: 'Nepal'
},
hobbies: ['Programming','Music','Sports']
}
csv = JsonToCsv(json,'-',"'",'.');
console.log(csv);
'name'.'company'.'profession'.'address-city'.'address-country'.'hobbies'
'Saimon Thada Magar'.'ChicMic, Mohali, India'.'Software Engineer'.'Khoptar -4, Rampur'.'Nepal'.'Programming'
''.''.''.''.''.'Music'
''.''.''.''.''.'Sports'
name | company | profession | address_city | address_country | hobbies |
---|---|---|---|---|---|
Saimon Thada Magar | ChicMic, Mohali, India | Software Engineer | Khoptar -4, Rampur | Nepal | Programming |
Music | |||||
Sports |
🔜 Custom column names instead of joined JSON keys.