A simple tool to find deeply nested values in JSON data structures.
npm i deep-nested-values
Returns a Boolean indicating whether the specified route exists within the object, and creates it if createRoute
is true
.
Returns the value at the specified route, or undefined
if not found.
Sets the value at the route. By default, it creates the route if it doesn't exist. Returns a Boolean indicating success or failure.
import { getDeepValue, setDeepValue, hasDeepValue } from 'deep-nested-vales';
const data = {
something: 'nothing',
value: 32,
nested: {
hello: 'world',
whatever: 'something',
deepnested: {
cat: 'meow',
someNumber: 1234
}
}
}
hasDeepValue(data, 'nested.deepnested.cat');
// returns true
getDeepValue(data, 'nested.deepnested.cat');
// returns 'meow'
setDeepValue(data, 'nested.deepnested.cat', 'purr');
// returns true
getDeepValue(data, 'nested.deepnested.cat');
// returns 'purr'