
Security News
How Enterprise Security Is Adapting to AI-Accelerated Threats
Socket CTO Ahmad Nassri discusses why supply chain attacks now target developer machines and what AI means for the future of enterprise security.
Dottie helps you easily (and without sacrificing too much performance) look up and play with nested keys in objects, without them throwing up in your face.
Not actively maintained. You are likely better off using lodash or ES6+
npm install dottie
For detailed usage, check source or tests.
Gets nested value, or undefined if unreachable, or a default value if passed.
var values = {
some: {
nested: {
key: 'foobar';
}
},
'some.dot.included': {
key: 'barfoo'
}
}
dottie.get(values, 'some.nested.key'); // returns 'foobar'
dottie.get(values, 'some.undefined.key'); // returns undefined
dottie.get(values, 'some.undefined.key', 'defaultval'); // returns 'defaultval'
dottie.get(values, ['some.dot.included', 'key']); // returns 'barfoo'
Note: lodash.get() also works fine for this
Sets nested value, creates nested structure if needed
dottie.set(values, 'some.nested.value', someValue);
dottie.set(values, ['some.dot.included', 'value'], someValue);
dottie.set(values, 'some.nested.object', someValue, {
force: true // force overwrite defined non-object keys into objects if needed
});
Transform object from keys with dottie notation to nested objects
var values = {
'user.name': 'Gummy Bear',
'user.email': 'gummybear@candymountain.com',
'user.professional.title': 'King',
'user.professional.employer': 'Candy Mountain'
};
var transformed = dottie.transform(values);
/*
{
user: {
name: 'Gummy Bear',
email: 'gummybear@candymountain.com',
professional: {
title: 'King',
employer: 'Candy Mountain'
}
}
}
*/
var values = {
'user_name': 'Mick Hansen',
'user_email': 'maker@mhansen.io'
};
var transformed = dottie.transform(values, { delimiter: '_' });
/*
{
user: {
name: 'Mick Hansen',
email: 'maker@mhansen.io'
}
}
*/
var object = {
a: 1,
b: {
c: 2,
d: { e: 3 }
}
};
dottie.paths(object); // ["a", "b.c", "b.d.e"];
0.3.1 and up ships with dottie.memoizePath: true by default, if this causes any bugs, please try setting it to false
lodash.get is a method from the Lodash library that allows you to access deep properties of an object safely. It is similar to dottie's get function but is part of a larger utility library.
deep-get-set is a small library that provides get and set functions for deep properties of an object, similar to dottie. It does not have as many features as dottie but is lightweight.
object-path is another utility that provides access to deep properties using a similar dot notation. It offers a rich set of methods like dottie and includes additional functionality such as del (delete) and has (check existence).
FAQs
Fast and safe nested object access and manipulation in JavaScript
We found that dottie 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
Socket CTO Ahmad Nassri discusses why supply chain attacks now target developer machines and what AI means for the future of enterprise security.

Security News
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.

Security News
Experts push back on new claims about AI-driven ransomware, warning that hype and sponsored research are distorting how the threat is understood.