Skip to content

bibekluitel/json-flat

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Json-Tree Flat

Use this library to flatten your tree Json. Provided the key for branching node in json we can obtain a flatten object with path to object as a key hash

Usage

const  flatTree = require('flat-json');

const data = [
  {
    "title": "folder_1",
    "type": "folder",
    "permission": true,
    "children": [
      {
        "title": "file_1",
        "type": "sketch"
      },
      {
        "title": "file_2",
        "type": "pdf"
      }
    ]
  }
]

const output = flatTree(data, 'children');

// Output:

// { 
//   '0': { 
//     title: 'folder_1', 
//     type: 'folder', 
//     permission: true 
//   },
//   '0.children.0': { 
//     title: 'file_1', 
//     type: 'sketch' 
//   },
//   '0.children.1': { 
//     title: 'file_2', 
//     type: 'pdf'
//   }
// }

About

Flatten your json according as desired.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published