
Security News
Django Joins curl in Pushing Back on AI Slop Security Reports
Django has updated its security policies to reject AI-generated vulnerability reports that include fabricated or unverifiable content.
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 find-object-paths
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 'find-object-paths';
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 2,805 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
Django has updated its security policies to reject AI-generated vulnerability reports that include fabricated or unverifiable content.
Security News
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
Security News
A new Node.js homepage button linking to paid support for EOL versions has sparked a heated discussion among contributors and the wider community.