1.0.2 • Published 8 years ago

csvtojsontree v1.0.2

Weekly downloads
4
License
MIT
Repository
github
Last release
8 years ago

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:

SampleInputTable
File:
Rootname
Children
Child1name
Children
Child1.1name
Child1.2name
Child1.2name
Child2name
Children
Child2.1name
Child2.2name
Child2.3name

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

1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago