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-list-paths

v1.0.0

Published

Traverse through a JSON object and get a list of all keys and paths.

Readme

JSON List Paths

A node.js utility to iterate through a JSON object and retrieve a list of all available paths. As well as property type and values.

Install

npm install json-list-paths

Usage

Pass a parsed JSON object to the function and will return a JSONPathList object. See methods below for usefullness.

var jlp = require('json-list-paths')

var json = {
    a: 'abc',
    b: 123,
    c: {},
    d: []
}
jlp(json);

Methods

get (path)

Returns the JSONPathList object matching that key.

list ([options])

With no options the list method will return a string array of all the available paths in the object with a few notable identifiers. A [] in the path indicates that the previous key was an array and any elements afterwards were found in a child of that array. When using the reduce method you will come across {} in the keys indicated that previous object was collapsed.

Options

  • types [boolean, number] *optional - Returns types each path was found to have. As well as including some added types like number-int, string-int, number-decimal, string-decimal. That further add clarity to what type of values where found. If true or 0 will return all types, a number will return n amount per path.
  • values [boolean, number] *optional - Returns primitive values each path was found to have. If true or 0 will return all values, a number will return n amount per path.
  • children [boolean, number] *optional - Returns object properties if any for each path. If true or 0 will return all values, a number will return n amount per path.
  • keys [boolean, number] *optional - Is like children but returns properties for collapsed paths. See Reduce. If true or 0 will return all values, a number will return n amount per path.

reduce (options)

The reduce method is used to collapse object properties down to one. This is useful if you have a JSON object that uses an id for the key (an example might be an object with SKUs as the the keys). Objects that are collapsed will have {}in place of where the keys would have been in the path.

Options

  • keylimit [number] * optional - If an object has more keys than this number that it will be collapsed.
  • match [array] * optional - This is an array of strings or regular expressions that will be used to evalute each path, to see if it's child properties should collapse.
  • replace [array] * optional - This is an array of objects that will rewrite a given key, if the parent path and key match the values supplied.
    • path [string, regular expression] - The parent path to match.
    • key [string, regular expression] - The key to match.
    • replace [string] - The string to replace with.
    • stop [boolean] - Stop all further replacements.

Examples

Using all available options for list

var jlp = require('json-list-paths');

var json = {
    items: {
        'PN1234': {
            name: 'Item 1',
            value: 12,
            quantity: 12
        },
        'PN123452': {
            name: 'Item 2',
            value: 10,
            quantity: 1
        },
        'G123': {
            name: 'Item 3',
            value: 20,
            quantity: 4
        }
    },
    total: {
        items: 3,
        quantity: 17,
        value: 234
    }

}
jlp(json)
    .reduce({
        match: ['.items']
    })
    .list({
        keys: true,
        values: true,
        types: true,
        children: true

    });

// {
//     '.': {
//         types: ['object'],
//         children: ['items', 'total']
//     },
//     '.items': {
//         types: ['object'],
//         children: ['{}']
//     },
//     '.items.{}':
//         {
//             types: ['dictionary', 'object'],
//             keys: ['PN1234', 'PN123452', 'G123'],
//             children: ['name', 'value', 'quantity']
//         },
//     '.items.{}.name':
//         {
//             values: ['Item 1', 'Item 2', 'Item 3'],
//             types: ['string']
//         },
//     '.items.{}.value': {
//         values: ['10', '12', '20'],
//         types: ['number-int']
//     },
//     '.items.{}.quantity': {
//         values: ['1', '4', '12'],
//         types: ['number-int']
//     },
//     '.total':
//         {
//             types: ['object'],
//             children: ['items', 'quantity', 'value']
//         },
//     '.total.items': {
//         values: ['3'],
//         types: ['number-int']
//     },
//     '.total.quantity': {
//         values: ['17'],
//         types: ['number-int']
//     },
//     '.total.value': {
//         values: ['234'],
//         types: ['number-int']
//     }
// }

Using regular expressions reduce replace option

var json = {
    items: {
        'PN1234': {
            name: 'Item 1',
            value: 12,
            quantity: 12,
            main: true
        },
        'PN123452': {
            name: 'Item 2',
            value: 10,
            quantity: 1
        },
        'G123': {
            name: 'Item 3',
            value: 20,
            quantity: 4,
            style: 'g'
        }
    },
    total: {
        items: 3,
        quantity: 17,
        value: 234
    }

}

jlp(json)
    .reduce({
        replace: [{
            path: '.items',
            key: /^([A-Z]+).*/,
            replace: '$1_n',
            stop: true
        }]
    })
    .list();
    
// Result: 
// [
//     '.',
//     '.items',
//     '.items.PN_n',
//     '.items.PN_n.name',
//     '.items.PN_n.value',
//     '.items.PN_n.quantity',
//     '.items.PN_n.main',
//     '.items.G_n',
//     '.items.G_n.name',
//     '.items.G_n.value',
//     '.items.G_n.quantity',
//     '.items.G_n.style',
//     '.total',
//     '.total.items',
//     '.total.quantity',
//     '.total.value'
// ]