New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

treeize

Package Overview
Dependencies
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

treeize

Converts tabular row data (as from SQL joins, flat JSON, etc) to deep tree graphs based on simple column naming conventions.

  • 0.0.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
919
increased by7.86%
Maintainers
1
Weekly downloads
 
Created
Source

treeize

v0.0.3

Converts row data (in JSON/associative array format) to object/tree structure based on column naming conventions.

Installation

npm install --save treeize

Usage

Treeize currently has a single function, grow, that takes your results/rows of flat associative data and returns a full object graph;

  • The column/attribute order is not important. All attributes are sorted by depth before mapping.
  • To imply a collection, use a plural name (e.g. "subjects" instead of "subject"). Otherwise, use a singular name.
  • Use a + to seperate path nodes (e.g. "toys+name" implies a "toys" collection on a root level item. Each toy item would have [at least] a "name" attribute)
var treeize = require('treeize');

var flatData = [
  {
    "name":             "Mittens",
    "age":              12,
    "toys+name":        "mouse",
    "toys+owner+name":  "Mittens"
  },
  {
    "name":             "Mittens",
    "age":              12,
    "toys+name":        "yarn",
    "toys+owner+name":  "Ms. Threadz"
  },
  {
    "name":             "Tiger",
    "age":              7,
    "toys+name":        "a stick",
    "toys+owner+name":  "Mother Nature"
  }
];

var converted = treeize.grow(flatData);

Output

[
  {
    "name": "Mittens",
    "age": 12,
    "toys": [
      {
        "name": "mouse",
        "owner": {
          "name": "Mittens"
        }
      },
      {
        "name": "yarn",
        "owner": {
          "name": "Ms. Threadz"
        }
      }
    ]
  },
  {
    "name": "Tiger",
    "age": 7,
    "toys": [
      {
        "name": "a stick",
        "owner": {
          "name": "Mother Nature"
        }
      }
    ]
  }
]

Keywords

FAQs

Package last updated on 02 Sep 2013

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc