object-scan
object-scan allows traversal of complex javascript objects to find specific keys.
In web scraping, it's useful for parsing large, nested JSON datasets for specific datafields. object-scan can be used to recursively find any key in any object structure:
import objectScan from 'object-scan';
const haystack = { a: { b: { c: 'd' }, e: { f: 'g' } } };
objectScan(['a.*.f'], { joined: true })(haystack);
// => [ 'a.e.f' ]
Example Use
const objectScan = require('object-scan');
const myNestedObject = {
level1: {
level2: {
level3: {
myTargetKey: 'value',
},
},
},
};
const searchTerm = 'myTargetKey';
const result = objectScan([`**.${searchTerm}`], { joined: false })(myNestedObject);
console.log(result);