Skip to content

safjanowski/json-query-parser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JSON query parser Build Status

Tool for build chainable queries to retrive data from JSON structure.

Supported methods

  • find(string || function)
  • filter(string || function)
  • children()
  • names()

Examples of use

drinks = [
  {
    'name': 'Soft Drinks',
    'leaf': [
      {
        'name': 'Bottled',
        'leaf': [
          {
            'name': 'Apple',
            'leaf': [
              {
                'name': 'Apple 500 ML'
              },
              {
                'name': 'Apple 1 Ltr'
              }
            ]
          }
        ]
      },
      {
        'name': 'Fountain',
        'leaf': [
          {
            'name': 'Apple',
            'leaf': [
              {
                'name': 'Apple Regular, 500 ML'
              }
            ]
          }
        ]
      },
      {
        'name': 'Tin',
        'leaf': [
          {
            'name': 'Apple',
            'leaf': [
              {
                'name': 'Apple Regular, 300 ML'
              }
            ]
          }
        ]
      }
    ]
  }
];

parser(drinks).find('Soft Drinks').find('Fountain').children().names(); 
// [ 'Apple' ]

parser(drinks).find('Soft Drinks').find('Fountain').find('Apple').children().names(); 
// [ 'Apple Regular, 500 ML' ]

parser(drinks).find('Soft Drinks').find('Apple')
    .children().filter(function(node) {
         return node.name.match(/500/);
      }).names(); 
// [ 'Apple 500 ML', 'Apple Regular, 500 ML' ]

Run tests

  • make test – runs test and wathing for changes in JS files

About

JSON query parser

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published