Skip to content

object-scan

153 8 13 MIT
19.0.5 (6 Oct 2023) Jun 10 2018 101.2 thousand (month)

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);

Alternatives / Similar


Other Languages

1,972 1.0.1 (1 year, 5 months ago) Feb 09 2022 compare
477 1.6.0 (2 months ago) Feb 09 2022 compare
207 0.2.25 (1 year, 4 months ago) Feb 09 2022 compare
2,102 0.2.13 (20 days ago) May 19 2011 compare
1,712 4.0.0 (2 years ago) Apr 18 2015 compare