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

jsoncrawler

v0.2.1

Published

jsoncrawler.js lets you search complex json data

Readme

jsoncrawler

jsoncrawler is a simple module that search/replace data inside complex javascript objects

Getting started

Add script tag in your header

<script src="https://cdn.jsdelivr.net/npm/jsoncrawler@latest/jsoncrawler.js"></script>

Or on node.js or webpack based projects:

npm i jsoncrawler

And in your javascript:

import jsonCrawler from 'jsoncrawler';

Parameters

function jsonCrawler(
    object_to_search: {[key:string]: any} | any[],
    value_to_search: Array<number | string | boolean>,
    options: {
        replace: Array<number | string | boolean>, // Value to replace. Must be in the same order as the search array.
        filter: Array<number | string> // Key names or index numbers to exclude from search/replacement
    }): {
        path: Array<number | string>, // Nested key path in order to the parent location
        key: string | number, // Key names or index number of the parent value
        siblings: Array<number | string>, // Key names or index numbers of the siblings that are present on the same level
        value: number | string | boolean // Value you have searched
    }[]

Full scan

You can scan the whole object and get the key path, key name, siblings and value

Example

let obj = {
    artist: "DIA",
    tracks: [
        "Paradise",
        {
            hidden: "Come On Down"
        }
    ]
}

let result = jsonCrawler(obj);

/*
result returns:
[
  { path: [], key: 'artist', siblings: [ 'tracks' ], value: 'DIA' },
  { path: [ 'tracks' ], key: 0, siblings: [ 1 ], value: 'Paradise' },
  {
    path: [ 'tracks', 1 ],
    key: 'hidden',
    siblings: [],
    value: 'Come On Down'
  }
]
*/

Searching value

Search and locate value inside complex json object

Example

// Let's find value "DIA" and "Come On Down"

let obj = {
    artist: "DIA",
    tracks: [
        "Paradise",
        {
            hidden: "Come On Down"
        }
    ]
}

let result = jsonCrawler(obj, ["Come On Down", "DIA"]);

/*
result returns:
[
  { path: [], key: 'artist', siblings: [ 'tracks' ], value: 'DIA' },
  {
    // 'path' is the key path to the data location:
    path: [ 'tracks', 1 ],
    
    // 'key' is the key name of the value
    key: 'hidden',
    
    // 'siblings' is the key names that are present on the same level
    siblings: [],
    
    // 'value' is the value you have searched
    value: 'Come On Down'
  }
]

Note: search results does not come in order.
*/

// to get to the searched data:

let ComeOnDown = obj;

result[1].path.forEach(p => {
    // dive in to the key path
    ComeOnDown = ComeOnDown[p];
});

// your value is in the key
ComeOnDown = ComeOnDown[result[1].key];

let DIA = obj;
result[0].path.forEach(p => {
    DIA = DIA[p];
});
DIA = DIA[result[0].key];

Replacing value

You can replace the value easily

Example

let replace = ['Linux', 'Ubuntu', ['Mint', {mini: ['Lubuntu', 'linux']}]];

// replace 'Lubuntu' with 'Xubuntu' and 'Linux' with 'Linus'
// Make sure the search array and replace array values are in the same order.

jsonCrawler(replace, ['Lubuntu', 'Linux'], {
    replace: ['Xubuntu', 'Linus']
});

console.log(replace);
// returns ["Linus","Ubuntu",["Mint",{"mini":["Xubuntu","linux"]}]]

Filtering keys

You can exclude your search/replacement in certain key names or index numbers

Example

let replace = ['Linux', 'Ubuntu', ['Mint', {mini: ['Lubuntu', 'linux']}]];

// replace 'Lubuntu' with 'Xubuntu' and 'Linux' with 'Linus'
// but exclude data inside keyname 'mini'
 
jsonCrawler(replace, ['Lubuntu', 'Linux'], {
    replace: ['Xubuntu', 'Linus'],
    filter: ['mini']
});

console.log(replace);
// returns ["Linus","Ubuntu",["Mint",{"mini":["Lubuntu","linux"]}]]