Skip to content

fatgeekuk/jsonaught

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

jsonaught

JSON recursive search library (available on npm jsonaught

If you have a large and deep JSON structure and you want to find something in it, this is the library for you.

Installation

$ npm install jsonaught

Example

Say you have an annoying JSON structure.

var data = [
  {tag: 'td'},
  {tag: 'inner', children: [{tag: 'td'}]},
  {tag: 'other', children: [{tag: 'td'}]},
  {
    tag: 'outer',
    children1: [
      {tag: 'inner', children: [{tag: 'td', hit: 'first'}]}
    ],
    other: {tag: 'td'},
    another: {tag: 'inner', other: {tag: 'td', hit: 'second'}}
  }
]

And you want to find all the {tag: 'td'} elements that are somewhere within an element that has {tag: 'inner'} which is itself somewhere inside an element that has {tag: 'outer'}.

You can find these by defining a query and calling the library

// ES6 format
var query = [
  {
    tag: 'outer'
  },
  {
    tag: 'inner'
  },
  {
    tag: 'td'
  }
];

result = (new JSONaught(data)).search(...query);

Or, in good old ES5

// ES5 format
result = (new JSONaught(data)).search({
    tag: 'outer'
  },
  {
    tag: 'inner'
  },
  {
    tag: 'td'
  });

Either of these should return an array of references to the two elements of the data JSON that satisfy the query.

About

JSON recursive search library

Resources

Stars

Watchers

Forks

Packages

No packages published