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-find

v2.0.8

Published

Searches a JSON document or JSON compatible object for a given key.

Downloads

7,401

Readme

No longer maintained. Please check out transfigure-json instead.


JSON-FIND

The goal of the module is provide easy access to JSON or JSON-compatible* values. This is not intended for complex JSON queries, but rather for retrieving specifc values without the need to constantly reference a file's structure. In other words, if you are treating JSON as a database and making multiple queries on the same file, this is not for you. However, if you need to get information from JSON data such as from reasonably consistent web API calls where the structure of the data can undergo subtle structural changes, then this module aims to provide a convenient way to access that data.

*a JSON-compatible object means the contents of the object can only be:

  • Booleans
  • Numbers
  • Strings
  • Objects (of valid JSON)
  • Arrays (of valid JSON)

API

Instantiation

/* CommonJS */
const JsonFind = require("json-find");
/* ES6 */
import JsonFind from "json-find";

const test = {
  a: 1,
  b: 2,
  c: [
    3,
    4,
    {
      d: {
        e: 5,
      },
      f: {
        e: 8,
      },
    },
  ],
  d: 7,
};

const doc = JsonFind(test);

If passed invalid JSON, JsonData will throw an error. If passed a Number/String/Boolean/null, JsonData will simply return the given argument.


#.checkKey(Object, String) -> JSON or False

Performs a depth-first search for the given key and returns its value, otherwise false.

doc.checkKey("g"); // false
doc.checkKey("e"); // 5
doc.checkKey("f"); // { e: 8 }

#.findValues(Object, ...String) -> Object

Searches the given Object for each key given. If a given key exists in the Object, its key/value pair are copied to the resulting Object. If none are matched, an empty Object is returned.

If given an Object with multiple identical keys, the value of the first matching key found will be returned, ignoring the others. However, if identical keys exist on the same level within an Object, the value of the last key will be returned.

doc.findValues("z"); // {}
doc.findValues("z", "d"); // { "d": { "e": 5 } }
doc.findValues("a", "d"); // { "a": 1, "d": { "e": 5 } }

// a.c[2].d.e has already been retrieved,
// so the value of the first matching key encountered
// by the search for "e" is 8
doc.findValues("d", "e"); // { "d": { "e": 5 }, "e": 8 }

#.extractPaths([...String] or False, ...[...String]) -> Object

Extracts the values from JSON at given paths and returns a new Object with values at the given keys. A Path is an Array-of-String|Number, consisting of all keys (including Array indexes) from a root key to the key for the desired value.

The first parameter is an Array of new keys names. If no new names are necessary, false maybe be passed instead.

After the new keys parameter, an arbitrary number of Paths maybe passed. If no new keys are passed, the keys for the returned Object will be the last item in each Path. If there are more Paths than keys, the original keys are used assigned to values without a new key. If there are more new keys than Paths, null is assigned to the extra new keys. If the same key is reused, the key is renamed key + index.

const test = {
  c: 1,
  b: [
    { c: 2, d: 4, e: "two" },
    { c: 3, d: 6 },
    { c: 4, d: 8, e: "four" },
    { c: 5, d: 10 },
  ],
  f: "six",
  g: {
    h: "eight",
    i: [{ j: "ten" }],
  },
};

const doc = JsonFind(test);

doc.extractPaths(false, ["b", 3, "c"]); // { c: 5 }
doc.extractPaths(
  ["f is", "h is", "j is"], // new keys to be assigned
  ["f"], // paths given
  ["g", "h"],
  ["g", "i", 0, "j"]
);
// { 'f is': 'six', 'h is': 'eight', 'j is': 'ten' }

/* more Paths than keys */
doc.extractPaths(["a", "b"], ["b", 0, "c"], ["b", 1, "c"], ["b", 2, "c"]);
// { a: 2, b: 3, c: 4 }

/* same key reused */
doc.extractPaths(false, ["b", 0, "c"], ["b", 1, "c"], ["b", 2, "c"]);
// { c: 2, "c+1": 3, "c+2": 4 }

/* more keys than Paths */
doc.extractPaths(["a", "b", "c"], ["f"], ["g", "i"]);
// { a: 'six', b: { h: 'eight', i: [{ j: 'ten' }] }, c: null }

/* accessing all items in an Array */
doc.b.map((obj, index) => doc.extractPaths(["c is"], ["b", index, "c"]));
// [{ 'c is': 2 }, { 'c is': 3 }, { 'c is': 4 }, { 'c is': 5 }]