Convert JSON into CSV
___ _________ __________ _____ ___
/\ \ /\ _____\ /\ ____ \ /\ \ /\ \
\ \ \ \ \ \____/ \ \ \__/\ \ \ \ \ \ \ \ \
\ \ \ \ \ \_______ \ \ \ \ \ \ \ \ \\ \\ \ \
__ \ \ \ \ \_______ \ \ \ \ \ \ \ \ \ \ \ \ \ \
/\ \ \ \ \ \/______/\ \ \ \ \ \ \ \ \ \ \\ \ \\ \
\ \ \_\_\ \ ____\_\ \ \ \ \_\_\ \ \ \ \ \ \ \ \
\ \_________\ /\_________\ \ \_________\ \ \__\ \ \____\
\/_________/ \/_________/ \/_________/ \/__/ \/____/
____________ __________
/\____ ____\ /\ ____ \
\/___/\ \___/ \ \ \__/\ \
\ \ \ \ \ \ \ \ \
\ \ \ \ \ \ \ \ \
\ \ \ \ \ \ \ \ \
\ \ \ \ \ \_\_\ \
\ \__\ \ \_________\
\/__/ \/_________/
_________ _________ ___ ___
/\ _____\ /\ _____\ /\ \ /\ \
\ \ \____/ \ \ \____/ \ \ \ \ \ \
\ \ \ \ \ \_______ \ \ \ \ \ \
\ \ \ \ \_______ \ \ \ \ \ \ \
\ \ \ \/______/\ \ \ \ \ \/ /
\ \ \______ ____\_\ \ \ \ \/ /
\ \________\ /\_________\ \ \____/
\/________/ \/_________/ \/___/
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.
New Features
✅ Custom key separator 💥
✅ Custom text delimiter and text separator 💥
Setup process
npm install convert-json-into-csv --save
Function Parameters
- 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
,
.
Use Method
Example 1 :
; //ES6//ORconst JsonToCsv = ; //ES5 let csv = ``;let json = name: 'Saimon Thada Magar' company: 'ChicMic, Mohali, India' profession: 'Software Engineer' address: city: 'Khoptar -4, Rampur' country: 'Nepal' csv = ;console;
Output (return value):
"name","company","profession","address_city","address_country"
"Saimon Thada Magar","ChicMic, Mohali, India","Software Engineer","Khoptar -4, Rampur","Nepal"
CSV Tabular View:
name | company | profession | address_city | address_country |
---|---|---|---|---|
Saimon Thada Magar | ChicMic, Mohali, India | Software Engineer | Khoptar -4, Rampur | Nepal |
Example 2 :
; //ES6//ORconst JsonToCsv = ; //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 = ;console;
Output (return value):
'name'.'company'.'profession'.'address-city'.'address-country'.'hobbies'
'Saimon Thada Magar'.'ChicMic, Mohali, India'.'Software Engineer'.'Khoptar -4, Rampur'.'Nepal'.'Programming'
''.''.''.''.''.'Music'
''.''.''.''.''.'Sports'
CSV Tabular View:
name | company | profession | address_city | address_country | hobbies |
---|---|---|---|---|---|
Saimon Thada Magar | ChicMic, Mohali, India | Software Engineer | Khoptar -4, Rampur | Nepal | Programming |
Music | |||||
Sports |
Upcoming new Features
🔜 Custom column names instead of joined JSON keys.