convert-json-into-csv
TypeScript icon, indicating that this package has built-in type declarations

1.1.18 • Public • Published

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

  1. JSON object [Object:Required] :- a JSON object which you want to convert to csv.
  2. Key Separator [String:Optional] :- a symbol to separate the JSON key names of parent and child object. Default value is _.
  3. Delimeter [String:Optional] :- a symbol to wrap the CSV value. Default value is ".
  4. Value Separator [String:Optional] :- a symbol to separate the diffent values of CSV. Default value is ,.

Use Method

Example 1 :

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);

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 :

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);

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.

Package Sidebar

Install

npm i convert-json-into-csv

Weekly Downloads

6

Version

1.1.18

License

MIT

Unpacked Size

9.58 kB

Total Files

5

Last publish

Collaborators

  • chsstm