0.1.5 • Published 7 years ago

@mojule/json-dom-plugins v0.1.5

Weekly downloads
1
License
MIT
Repository
github
Last release
7 years ago

json-dom-plugins

Plugins for json-tree that let you treat JSON like a DOM. Built on dom-plugins.

Wait, what?

It's more useful than you might think - using query selectors to find things in an object graph for example:

{
  "name": "backpack",
  "weight": 1,
  "contents": [
    {
      "name": "apple",
      "weight": 0.85
    }
  ]
}
const tree = JsonTree( json )
const weightNodes = tree.querySelectorAll( 'number.weight' )

const totalWeight = weightNodes.reduce(
  ( sum, node ) => sum + node.nodeValue(),
  0
)

console.log( totalWeight ) // 1.85

Install

npm install @mojule/json-dom-plugins

Example

const { Factory } = require( '@mojule/json-tree' )
const domPlugins = require( '@mojule/json-dom-plugins' )
const json = require( './path/to/my.json' )

const Tree = Factory( domPlugins )
const tree = Tree( json )

const weightNodes = tree.querySelectorAll( 'number.weight' )
// etc
0.1.5

7 years ago

0.1.4

7 years ago

0.1.3

7 years ago

0.1.2

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago