Loading...

Convert JSON 2 CSV in JavaScript

:heavy_exclamation_mark: This post is older than a year. Consider some information might not be accurate anymore. :heavy_exclamation_mark:

json2csv is java script library which allows conversion of the format csv and json on a linux terminal.

Installation

Install it with npm

npm -g json2csv

CLI

A quick demonstration

test-data.json

[
  {
    "_id": "5971ebce9b51d3f1afee6a34",
    "index": 0,
    "guid": "c48c4f70-e825-4be9-a1a9-63a145dc469d",
    "isActive": false
  },
  {
    "_id": "5971ebce3dc681e6c106cca5",
    "index": 1,
    "guid": "3f3ad5d9-f59b-4f79-92c6-b589fc29a3a5",
    "isActive": false
  },
  {
    "_id": "5971ebce96c43c94c6b984de",
    "index": 2,
    "guid": "ac24adb1-1c74-4f1f-ba6c-c108f76941f4",
    "isActive": false
  }
]

Export to CSV

$ json2csv -i test-data.json -o output.csv

The above input will result in this output:

"_id","index","guid","isActive"
"5971ebce9b51d3f1afee6a34",0,"c48c4f70-e825-4be9-a1a9-63a145dc469d",false
"5971ebce3dc681e6c106cca5",1,"3f3ad5d9-f59b-4f79-92c6-b589fc29a3a5",false
"5971ebce96c43c94c6b984de",2,"ac24adb1-1c74-4f1f-ba6c-c108f76941f4",false
Please remember the terms for blog comments.