PHPackages                             loilo/jsonpath - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. loilo/jsonpath

ActiveLibrary

loilo/jsonpath
==============

Runs RFC9535 compatible JSONPath queries against a data set

0.3.1(3mo ago)01.7k↓36.1%11MITPHPPHP ^8.0CI passing

Since Feb 19Pushed 3mo ago1 watchersCompare

[ Source](https://github.com/loilo/jsonpath-php)[ Packagist](https://packagist.org/packages/loilo/jsonpath)[ RSS](/packages/loilo-jsonpath/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (3)Versions (6)Used By (1)

 [![The jsonpath-php logo: an LED matrix panel displaying the characters "{ $ }" as glowing yellow dots](jsonpath.png)](jsonpath.png)

jsonpath-php
============

[](#jsonpath-php)

*An implementation of RFC 9535 [JSONPath](http://goessner.net/articles/JsonPath/)*

[![Tests](https://camo.githubusercontent.com/47b30dfe8ebd611a5d93541f5819135b35e21724d98c4920ee4e7884025b396c/68747470733a2f2f62616467656e2e6e65742f6769746875622f636865636b732f6c6f696c6f2f6a736f6e706174682d7068702f6d61696e)](https://github.com/loilo/jsonpath-php/actions/workflows/test.yml)[![Packagist](https://camo.githubusercontent.com/184bcb1f364ffba2c772061211ee1479c35070257070843b392ed8b81acd6f4c/68747470733a2f2f62616467656e2e6e65742f7061636b61676973742f762f6c6f696c6f2f6a736f6e70617468)](https://packagist.org/packages/loilo/jsonpath)[![PHP Version](https://camo.githubusercontent.com/ff2e5e1f3b1d6df26ff0243341c63f9bf52ea2d7c48c6079ca83a1d8bfd1e75d/68747470733a2f2f62616467656e2e6e65742f7061636b61676973742f7068702f6c6f696c6f2f6a736f6e70617468)](https://camo.githubusercontent.com/ff2e5e1f3b1d6df26ff0243341c63f9bf52ea2d7c48c6079ca83a1d8bfd1e75d/68747470733a2f2f62616467656e2e6e65742f7061636b61676973742f7068702f6c6f696c6f2f6a736f6e70617468)

This is a PHP implementation of JSONPath, a query language for JSON. It aims for 100% compatibilty with the JSONPath syntax standardized in [RFC 9535](https://datatracker.ietf.org/doc/rfc9535/).

Currently, this library passes 99% of the work-in-progress [JSONPath Compliance Test Suite](https://github.com/jsonpath-standard/jsonpath-compliance-test-suite) (with the test suite version on [Feb 21, 2025](https://github.com/jsonpath-standard/jsonpath-compliance-test-suite/tree/9cf4a7517828d4f18557959682a4767de4735f94)). All of the the missing 1% are UTF-16 related tests, which should not affect most day-to-day users (and which I'm not sure how to implement in PHP — any help is appreciated!)

Installation
------------

[](#installation)

```
composer require loilo/jsonpath
```

Note that at least PHP 8.0 is needed to use jsonpath-php. For technical reasons, unit tests are only run against PHP 8.2+.

Usage
-----

[](#usage)

```
use Loilo\JsonPath\JsonPath;

$query = new JsonPath('$.users[*].name');

$result = $query->find([
	'users' => [
		[ 'name' => 'John Doe' ],
		[ 'name' => 'Jane Doe' ],
	],
]);

print_r($result);

/*
Prints:

Array
(
	[0] => John Doe
	[1] => Jane Doe
)
*/

$path_result = $query->paths([
	'users' => [
		[ 'name' => 'John Doe' ],
		[ 'name' => 'Jane Doe' ],
	],
]);

print_r($path_result);

/*
Prints:

Array
(
	[0] => Loilo\JsonPath\PathResult Object
		(
			[value] => John Doe
			[path] => $['users'][0]['name']
		)

	[1] => Loilo\JsonPath\PathResult Object
		(
			[value] => Jane Doe
			[path] => $['users'][1]['name']
		)
)
*/

$path_segments_result = $query->path_segments([
	'users' => [
		[ 'name' => 'John Doe' ],
		[ 'name' => 'Jane Doe' ],
	],
]);

print_r($path_segments_result);

/*
Prints:

Array
(
	[0] => Loilo\JsonPath\PathSegmentsResult Object
		(
			[value] => John Doe
			[segments] => Array
				(
					[0] => users
					[1] => 0
					[2] => name
				)
		)

	[1] => Loilo\JsonPath\PathSegmentsResult Object
		(
			[value] => Jane Doe
			[segments] => Array
				(
					[0] => users
					[1] => 1
					[2] => name
				)
		)
)
*/
```

Development
-----------

[](#development)

### Project Scope

[](#project-scope)

Please note that I'm striving for feature parity with the [jsonpath-js](https://github.com/ashphy/jsonpath-js) library and therefore will add neither features nor fixes to the search logic that are not reflected in jsonpath-js itself.

If you have any issues with the library that are *not* obviously bugs in this PHP port, and you happen to know JavaScript, please check if your use case works correctly in the [online demo of jsonpath-js](https://jsonpath.com/) since that's the canonical implementation. If the issue appears there as well, please open an issue [in their repo](https://github.com/ashphy/jsonpath-js).

### Setup

[](#setup)

To start development on jsonpath-php, you need git, PHP (≥ 8.2), Composer and npm.

Since code is formatted using [Prettier](https://prettier.io/), it's also recommended to use an [editor which supports Prettier](https://prettier.io/docs/en/editors.html) formatting.

Clone the repository and `cd` into it:

```
git clone https://github.com/loilo/jsonpath-php.git
cd jsonpath-php
```

Install Composer dependencies:

```
composer install
```

Install npm dependencies. They are needed for code formatting and for compiling the [Peggy](https://peggyjs.org/) grammar.

```
npm ci

```

### Formatting the Code

[](#formatting-the-code)

The code is formatted using [Prettier](https://prettier.io/). To format the code, run:

```
npm run format
```

### Compiling the Grammar

[](#compiling-the-grammar)

The JSONPath grammar is defined in `src/grammar/rfc9535-parser.pegjs`. To compile it to `src/PeggyParser.php`, run:

```
npm run generate-parser
```

### Quality Assurance

[](#quality-assurance)

There are different kinds of code checks in place for this project. All of these are run when a pull request is submitted but can also be run locally:

CommandPurposeDescription`vendor/bin/phpcs`check code styleRun [PHP\_CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer) to verify that the source code abides by the [PSR-12](https://www.php-fig.org/psr/psr-12/) coding style.`vendor/bin/phpstan`static analysisRun [PHPStan](https://phpstan.org/) against the codebase to avoid type-related errors and unsafe coding patterns.`vendor/bin/pest`check program logicRun all [Pest](https://pestphp.com/) tests from the [`tests`](tests/) folder.Credit
------

[](#credit)

All the credit goes to the creator of [jsonpath-js](https://github.com/ashphy/jsonpath-js). They did all the hard conceptual work, this PHP library is merely a port of their code.

###  Health Score

39

—

LowBetter than 86% of packages

Maintenance79

Regular maintenance activity

Popularity22

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity37

Early-stage or recently created project

 Bus Factor1

Top contributor holds 95.2% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~85 days

Total

5

Last Release

112d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/b1da49bad9203cc40a34d975dc00c80af09452bee1da6413e2f1b8214b539675?d=identicon)[loilo](/maintainers/loilo)

---

Top Contributors

[![loilo](https://avatars.githubusercontent.com/u/1922624?v=4)](https://github.com/loilo "loilo (20 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (1 commits)")

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/loilo-jsonpath/health.svg)

```
[![Health](https://phpackages.com/badges/loilo-jsonpath/health.svg)](https://phpackages.com/packages/loilo-jsonpath)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
