csvtojsontree

1.0.2 • Public • Published

csvtojsontree

Description

Little utility that converts a csv file representing hierarchical data into a nested json object.

Takes hierarchical data from a spreadsheet that is exported as a csv file like this:

Sample Input Table
File:
Root name
Children
Child1 name
Children
Child1.1 name
Child1.2 name
Child1.2 name
Child2 name
Children
Child2.1 name
Child2.2 name
Child2.3 name

with corresponding csv that looks like this:

File:,,,
Root,name,,
Children,,,
,,,
,Child1,name,
,Children,,
,,,
,,Child1.1,name
,,,
,,Child1.2,name
,,,
,,Child1.3,name
,,,
,Child2,name,
,Children,,
,,,
,,Child2.1,name
,,,
,,Child2.2,name
,,,
,,Child2.3,name

And creates a nested JSON object out of it:

{
  "Root": "name",
  "Children": [
    {
      "Child1": "name",
      "Children": [
        {
          "Child1.1": "name"
        },
        {
          "Child1.2": "name"
        },
        {
          "Child1.3": "name"
        }
      ]
    },
    {
      "Child2": "name",
      "Children": [
        {
          "Child2.1": "name"
        },
        {
          "Child2.2": "name"
        },
        {
          "Child2.3": "name"
        }
      ]
    }
  ]
}

Installation

npm install --save csvtojsontree

Usage

const csvtojsontree = require('csvtojsontree');
csvtojsontree.parse(path_to_csv_file)
.then(tree => do_stuff_with_tree)
.catch(error => handle_error);

Contact

Author: Stephen Liu (stliu.webservices@gmail.com).

Readme

Keywords

Package Sidebar

Install

npm i csvtojsontree

Weekly Downloads

1

Version

1.0.2

License

MIT

Last publish

Collaborators

  • ssyl55