npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

json-walker

v1.0.16

Published

walks json object to find a property or set a property

Downloads

33

Readme

To install from npm: npm install --save json-walker

This module does two things.

  1. Finds json properties by name. The property can be on the top level or nested. You can look for Arrays, Objects, Numbers, Booleans, or Strings with a specified property name.

  2. Sets json properties by name. The property can be on the top level or nested. You can set Arrays, Objects, Numbers, Booleans, or Strings with a specified property name.

* If their are multiple properties of the same name and type, json-walker will find/set all of them.

Full example

var jw = require('json-walker'),
    fs = require('fs');
    
fs.readFile('stuff.json', function(err, data){
    var jsonObj = JSON.parse(data);
    jw.findBooleansByKey('isGood', jsonObj, function(err, results){
        if(results.length && results[0] === false) {
            jw.setBooleansByKey('isGood', jsonObj, true, function(err, modified){
                fs.writeFile('stuff.json', JSON.stringify(modified), function(err){
                    console.log('Modified value saved');
                });
            });
        } else {
            console.log('No boolean value with the \'isGood\' key!');
        }
    });
});

Finding functions

findObjectsByKey(propertyName, jsonObject, function(err, results))

Takes three arguments. The first is the property name that your'e looking for. The second is the json object you are looking in. The third is a callback function.

Returns an error object, and a results array that contains all matching objects.

var jw = require('json-walker');
var obj = {
    "top": {
        "funky": {
            "breath": true,
            "hair": false
        }
    },
    "mid": {
        "funky": {
            "bellybutton": true,
            "underwear": true
        }
    },
    "bottom": {
        "funky": {
            "feet": true
        }
    }
};

jw.findObjectsByKey('funky', obj, function(err, results){
    /**
     * returns the nested objects
     *  [
     *      { 
     *          "breath": true,
     *          "hair": false
     *      },
     *      {
     *          "bellybutton: true,
     *          "underwear": true
     *      {
     *          "feet": true,
     *      }
     *  ]
     */
    console.log(results);
});

findArraysByKey(propertyName, jsonObject, function(err, results))

Takes three arguments. The first is the property name that your'e looking for. The second is the json object you are looking in. The third is a callback function.

Returns an error object, and a results array containing all matching arrays.

var jw = require('json-walker');
var obj = {
    "top": {
        "funky": ["breath", "hair"]
    },
    "mid": {
        "funky": ["bellybutton","underwear"]
        
    },
    "bottom": {
        "funky": ["feet"]
    }
};

jw.findArraysByKey('funky', obj, function(err, results){
    /**
    *   returns the nested arrays
    *   [
    *       ["breath", "hair"],
    *       ["bellybutton","underwear"],
    *       ["feet"]
    *   ]
    */
    console.log(results);
});

findStringsByKey(propertyName, jsonObject, function(err, results))

Takes three arguments. The first is the property name that your'e looking for. The second is the json object you are looking in. The third is a callback function.

Returns an error object, and a results array containing all matching strings.

var jw = require('json-walker');
var obj = {
    "top": {
        "funky": "breath"
    },
    "mid": {
        "funky": "bellybutton"
        
    },
    "bottom": {
        "funky": "feet"
    }
};

jw.findStringsByKey('funky', obj, function(err, results){
    /**
    *   returns the nested strings
    *   [
    *       "breath", "bellybutton", "feet"
    *   ]
    */
    console.log(results);
});

findNumbersByKey(propertyName, jsonObject, function(err, results))

Takes three arguments. The first is the property name that your'e looking for. The second is the json object you are looking in. The third is a callback function.

Returns an error object, and a results array containing all matching numbers.

var jw = require('json-walker');
var obj = {
    "top": {
        "funky": 1
    },
    "mid": {
        "funky": 2
        
    },
    "bottom": {
        "funky": 3
    }
};

jw.findNumbersByKey('funky', obj, function(err, results){
    /**
    *   returns the nested numbers
    *   [
    *       1, 2, 3
    *   ]
    */
    console.log(results);
});

findBooleansByKey(propertyName, jsonObject, function(err, result))

Takes three arguments. The first is the property name that your'e looking for. The second is the json object you are looking in. The third is a callback function.

Returns an error object, and a results array containing all booleans.

var jw = require('json-walker');
var obj = {
    "top": {
        "funky": false
    },
    "mid": {
        "funky": true
        
    },
    "bottom": {
        "funky": false
    }
};
jw.findBooleansByKey('funky', obj, function(err, results){
    /**
    *   returns all properties of the same name
    *   [
    *       false,true,false
    *   ]
    */
    console.log(results);
});

findAllByKey(propertyName, jsonObject, function(err, result))

Takes three arguments. The first is the property name that your'e looking for. The second is the json object you are looking in. The third is a callback function.

Returns an error object, and a results array containing all matching properties.

var jw = require('json-walker');
var obj = {
    "obj": {
        "funky": {
            passed: true
        },
        "level2": {
            "funky": {
                "passed": true
            }
        }
    },
    "arry": {
        "funky": [],
        "level2": {
            "funky": []
        }
    },
    "str": {
        "funky": "js",
        "level2": {
            "funky": "js",
            "level3": {
                "funky": "js"
            }
        }
    },
    "num": {
        "funky": 15,
        "level2": {
            "funky": 15,
            "level3": {
                "funky": 15
            }
        }
    }
};

jw.findAllByKey('funky', obj, function(err, results){
    /**
    *   returns all properties of the same name
    *   [
    *       {"passed":true},{"passed":true},[],[],"js","js","js",15,15,15
    *   ]
    */
    console.log(results);
});

Setting functions

setObjectsByKey(propertyName, jsonObject, newValue, function(err, modifiedJsonObject))

Takes four arguments. The first is the property name that your'e looking for. The second is the json object you are looking in. The third is the new value. (The new value must be of the same type) The fourth is a callback function.

Returns an error object, and the modified object.

var jw = require('json-walker');

var obj = { 
    funky: {
        modified: false
    }
};

jw.setObjectsByKey('funky', obj, { modified: true }, function(err, modified){
    /**
    *   returns modified object
    *   {
    *       funky: {
    *           modified: true
    *       }
    *   }
    */
    console.log(modified);
});

setArraysByKey(propertyName, jsonObject, newValue, function(err, modified))

Takes four arguments. The first is the property name that your'e looking for. The second is the json object you are looking in. The third is the new value. (The new value must be of the same type) The fourth is a callback function.

Returns an error object, and the modified object.

var jw = require('json-walker');

var obj = { 
    funky: [
        1,2,3,4
    ]
};

jw.setObjectsByKey('funky', obj, [4,3,2,1], function(err, modified){
    /**
    *   returns modified object
    *   {
    *       funky: [
    *           4,3,2,1
    *       ]
    *   }
    */
    console.log(modified);
});

setStringsByKey(propertyName, jsonObject, newValue, function(err, modified))

Takes four arguments. The first is the property name that your'e looking for. The second is the json object you are looking in. The third is the new value. (The new value must be of the same type) The fourth is a callback function.

Returns an error object, and the modified object.

var jw = require('json-walker');

var obj = { 
    funky: 'one'
};

jw.setObjectsByKey('funky', obj, 'two', function(err, modified){
    /**
    *   returns modified object
    *   {
    *       funky: 'two'
    *   }
    */
    console.log(modified);
});

setNumbersByKey(propertyName, jsonObject, newValue, function(err, modified))

Takes four arguments. The first is the property name that your'e looking for. The second is the json object you are looking in. The third is the new value. (The new value must be of the same type) The fourth is a callback function.

Returns an error object, and the modified object.

var jw = require('json-walker');

var obj = { 
    funky: 15
};

jw.setObjectsByKey('funky', obj, 42, function(err, modified){
    /**
    *   returns modified object
    *   {
    *       funky: 42
    *   }
    */
    console.log(modified);
});

setBooleansByKey(propertyName, jsonObject, newValue, function(err, modified))

Takes four arguments. The first is the property name that your'e looking for. The second is the json object you are looking in. The third is the new value. (The new value must be of the same type) The fourth is a callback function.

Returns an error object, and the modified object.

var jw = require('json-walker');

var obj = { 
    funky: false
};

jw.setObjectsByKey('funky', obj, true, function(err, modified){
    /**
    *   returns modified object
    *   {
    *       funky: true
    *   }
    */
    console.log(modified);
});