@mojule/json-dom-plugins

0.1.5 • Public • Published

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

Readme

Keywords

none

Package Sidebar

Install

npm i @mojule/json-dom-plugins

Weekly Downloads

0

Version

0.1.5

License

MIT

Last publish

Collaborators

  • nrkn
  • andybell