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 🙏

© 2025 – Pkg Stats / Ryan Hefner

advanced-json-path

v1.0.8

Published

Inspired by Stefan Goessner's JSONPath with some enhancements

Downloads

231

Readme

advanced-json-path

Inspired by Stefan Goessner's JSONPath http://goessner.net/articles/JsonPath/ with some enhancements

Installation

First install node.js on your computer.

Then use the following command in command prompt:

npm install advanced-json-path

Quick Statrt Usage

var JSONPath = require('advanced-json-path');
var object = {
    EventURL: "/mod-tc-mk2",
    EventData: {
        Device: "MOD-TC-MK2",
        Status: "OK",
        Data: {
            Temperature: 23.75
        },
        I2C_Address: "0x23"
    }
};

var path = '$..Temperature';
var result = JSONPath(object, path);

console.log(result); // 23.75

JSONPath Expressions Basics

as described at http://goessner.net/articles/JsonPath/

JSONPath expressions always refer to a JSON structure in the same way as XPath expression are used in combination with an XML document. Since a JSON structure is usually anonymous and doesn't necessarily have a "root member object" JSONPath assumes the abstract name $ assigned to the outer level object.

JSONPath expressions can use the dot–notation

$.EventData.Data.Devices[0].Type

or the bracket–notation

$['EventData']['Data']['Devices'][0]['Type']

for input path.

JSONPath allows the wildcard symbol * for member names and array indices. It borrows the descendant operator '..' from E4X and the array slice syntax proposal [start:end].

Expressions of the underlying scripting language (< expression >) can be used as an alternative to explicit names or indices as in

$..Devices[(@.length-1)]

using the symbol '@' for the current object. Filter expressions are supported via the syntax ?(< boolean expression >) as in

$..Devices[?(@.Found==1)]

Nested JSONPath expressions can be used with {< expression >}

$..Devices[{$.EventData..Selected}]

Here is a complete overview of the JSONPath syntax elements.

Expression | Meaning -----------|-------- $ | Root Object @ | Current Object . | Child .. | Recursive children descent

  • | Any object/property [ ] | index or quoted child name [start : end] | slice operator ( ) | script expression ?( ) | filter expression { } | nested JSONPath expression

Examples

Object in JSON notation used in examples:

var object = {
	"EventURL": "/devices",
	"EventData": {
		"Device": "ESP8266",
		"Status": "OK",
		"Data": {
			"Selected": 3,
			"Devices": [
				{
					"Type": "UART",
					"URL": "/mod-rfid",
					"Found": 0
				},
				{
					"Type": "UART",
					"URL": "/mod-finger",
					"Found": 1
				},
				{
					"Type": "UART",
					"URL": "/mod-emtr",
					"Found": 0
				},
				{
					"Type": "NATIVE",
					"URL": "/button",
					"Found": 1
				},
				{
					"Type": "NATIVE",
					"URL": "/relay",
					"Found": 1
				},
				{
					"Type": "NATIVE",
					"URL": "/adc",
					"Found": 1
				},
				{
					"Type": "I2C",
					"URL": "/mod-rgb",
					"Found": 0,
					"ID": "0x64",
					"Addresses": []
				},
				{
					"Type": "I2C",
					"URL": "/mod-tc-mk2",
					"Found": 1,
					"ID": "0x27",
					"Addresses": [
						"0x23"
					]
				},
				{
					"Type": "I2C",
					"URL": "/mod-io2",
					"Found": 1,
					"ID": "0x23",
					"Addresses": [
						"0x21"
					]
				},
				{
					"Type": "I2C",
					"URL": "/mod-irda",
					"Found": 1,
					"ID": "0x54",
					"Addresses": [
						"0x24"
					]
				},
				{
					"Type": "SPI",
					"URL": "/mod-led-8x8-rgb",
					"Found": 1
				}
			]
		}
	}
}
// Dotted or bracket notation
JSONPath(object, "$.EventData.Device");
JSONPath(object, "$['EventData']['Device']");

// Result
"ESP8266"

// Recursive children descent
JSONPath(object, "$..Status");

// Result
"OK"

// Index
JSONPath(object, "$..Devices[0]");

// Result
{
	"Type": "UART",
	"URL": "/mod-rfid",
	"Found": 0
}

// Last device
JSONPath(object, "$..Devices[(@.length-1)]");

// Result
{
	"Type": "SPI",
	"URL": "/mod-led-8x8-rgb",
	"Found": 1
}

// Nested JSONPath expression as index
JSONPath(object, "$..Devices[{$.EventData..Selected}]");

// Result
{
	"Type": "NATIVE",
	"URL": "/button",
	"Found": 1
}

// Slice
JSONPath(object, "$..Devices[1:3]");

// Result
[
	{
		"Type": "UART",
		"URL": "/mod-finger",
		"Found": 1
	},
	{
		"Type": "UART",
		"URL": "/mod-emtr",
		"Found": 0
	}
]

// Filter expression
JSONPath(object, "$..Devices[?(@.Found == 1)]");

// Result
[
	{
		"Type": "UART",
		"URL": "/mod-finger",
		"Found": 1
	},
	{
		"Type": "NATIVE",
		"URL": "/button",
		"Found": 1
	},
	{
		"Type": "NATIVE",
		"URL": "/relay",
		"Found": 1
	},
	{
		"Type": "NATIVE",
		"URL": "/adc",
		"Found": 1
	},
	{
		"Type": "I2C",
		"URL": "/mod-tc-mk2",
		"Found": 1,
		"ID": "0x27",
		"Addresses": [
			"0x23"
		]
	},
	{
		"Type": "I2C",
		"URL": "/mod-io2",
		"Found": 1,
		"ID": "0x23",
		"Addresses": [
			"0x21"
		]
	},
	{
		"Type": "I2C",
		"URL": "/mod-irda",
		"Found": 1,
		"ID": "0x54",
		"Addresses": [
			"0x24"
		]
	},
	{
		"Type": "SPI",
		"URL": "/mod-led-8x8-rgb",
		"Found": 1
	}
]

// Filter using current object and nested JSONPath expression
JSONPath(object, "$..Devices[?({$.EventData.Status} == 'OK' && @.Type == 'SPI')]");

// Result
{
	"Type": "SPI",
	"URL": "/mod-led-8x8-rgb",
	"Found": 1
}