Skip to content

JavaScript function similar to CakePHP's Set::extract, uses XPath syntax to extract data subsets from an iterable

Notifications You must be signed in to change notification settings

gabrielgilini/jsextract

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 

Repository files navigation

This is an attempt to build a XPath data extractor which could be useful on handling JSON API's responses.

Given an array:
var arr = [
    {
        'foo': 'bar',
        'baz': { 'theNumber' : 42 }
    },
    {
        'foo': 'bar',
        'baz': { 'theNumber' : 84 }
    },
    {
        'foo': 'bar',
        'baz': { 'theNumber' : 168 }
    },
    {
        'foo': 'bar',
        'baz': { 'theNumber' : 336 }
    }
];

extract would be used as:

var extracted = extract('/baz/theNumber', arr);

Yielding - [ 42, 84, 168, 336 ]

Check out the index file to see it in action, extracting data from a REST request on Flickr's API

About

JavaScript function similar to CakePHP's Set::extract, uses XPath syntax to extract data subsets from an iterable

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages