
Security News
New CVE Forecasting Tool Predicts 47,000 Disclosures in 2025
CVEForecast.org uses machine learning to project a record-breaking surge in vulnerability disclosures in 2025.
find-object-paths
Advanced tools
Find paths in objects to given key('s), value('s) or key/value combinations
Easy to use zero dependency get or find paths in objects to given key('s), value('s) or key/value combinations. It is meant to interact nicely with lodash to quickly access or test values in objects, but can be used standalone as well.
Despite other projects you also can specify values to be searched for.
Install via npm
npm install findObjectPaths
acmeInc.json
{
"company": {
"name": "ACME INC",
"address": "1st Street, Toontown, TT",
"founded": "December 31st 1969",
"hasStocks": true,
"numberOfEmployees": 2,
"numberOfActors": 3
}
// see full content on github
}
import { has, findObjectPaths } from 'findObjectPaths';
class TestMe {
static async main() {
let acmeInc = {};
rawFileContent = fs.readFileSync(p.resolve(__dirname, 'acmeInc.json'), 'utf-8');
acmeInc = JSON.parse(rawFileContent);
let path = findObjectPaths(acmeInc, {key: 'founded'});
// company.founded
path = findObjectPaths(acmeInc, {value: 'December 31st 1969'});
// company.founded
const allPaths: string[] = findObjectPaths(acmeInc, {key: 'actorId'}) as string[];
/* [ 'actors[0].actorId',
'actors[1].actorId',
'actors[2].actorId',
'actors[3].actorId' ]
*/
const ceoPath = findObjectPaths(acmeInc, {key: 'isCEO', value: true});
// employees[0].isCEO
has(acmeInc, 'name', 'Hugo Boss');
// true
has(acmeInc, {value: 'Hugo Boss'});
// true
}
}
TestMe.main();
See more examples implemented in tests-findObjectPaths.
findObjectPaths can be used as a lodash mixin.
import _ from '../lib/FindObjectPathsMixin';
.
.
.
const path = _.findObjectPaths(acmeInc, {key: 'numberOfActors'});
// company.numberOfActors
path = _.findObjectPaths(acmeInc, {value: 'DVD'});
// distributionChannels[1][2]
if (_.has(acmeInc, _.findObjectPaths(acmeInc, {value: 'DVD'}))) {
const dvd = _.get(acmeInc, _.findObjectPaths(acmeInc, {value: 'DVD'}));
// do something
}
Tests can be found in /test
and run by jest. To run the tests call npm test
.
has
function to check availability of keys / values in objects or arraysFAQs
Find paths in objects to given key('s), value('s) or key/value combinations
The npm package find-object-paths receives a total of 1,914 weekly downloads. As such, find-object-paths popularity was classified as popular.
We found that find-object-paths demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
CVEForecast.org uses machine learning to project a record-breaking surge in vulnerability disclosures in 2025.
Security News
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
Research
Security News
Eight new malicious Firefox extensions impersonate games, steal OAuth tokens, hijack sessions, and exploit browser permissions to spy on users.