deep-search-json

3.0.0 • Public • Published

deep-search-JSON

js utility to find all instances of a key in an object and run a function on the parent object of each (with support for async functions) https://www.npmjs.com/package/deep-search-json

INSTALLATION

npm install deep-search-json

USAGE

const deepSearch = require(deep-search-json);
var obj = {
  a: "1"
  b: "2"
  myKey: "hello world"
  d: [
    ...,
    {
      ...
      myKey: "hello world"
    }
    ...,
    ]
}

var newObj = deepSearch(obj, "myKey", (obj) => obj.myKey = "HELLO WORLD");

/* NEW OBJECT
*  {
*    a: "1"
*    b: "2"
*    myKey: "HELLO WORLD"
*    d: [
*      ...,
*      {
*        ...
*        myKey: "HELLO WORLD"
*      }
*      ...,
*      ]
*  }
*
*/

Note

This does not natively support finding keys nested into each other eg: { myKey: { myKey: "hello world" } } will only find the outer level

Dependents (0)

Package Sidebar

Install

npm i deep-search-json

Weekly Downloads

19

Version

3.0.0

License

MIT

Unpacked Size

4.51 kB

Total Files

4

Last publish

Collaborators

  • davidmehani