PHPackages                             flow/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. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. flow/jsonpath

Abandoned → [softcreatr/jsonpath](/?search=softcreatr%2Fjsonpath)ArchivedLibrary[Parsing &amp; Serialization](/categories/parsing)

flow/jsonpath
=============

JSONPath implementation for parsing, searching and flattening arrays

0.5.0(6y ago)30615.6M—7.4%41[18 issues](https://github.com/FlowCommunications/JSONPath/issues)20MITPHPPHP &gt;=5.4.0

Since Sep 12Pushed 5y ago11 watchersCompare

[ Source](https://github.com/FlowCommunications/JSONPath)[ Packagist](https://packagist.org/packages/flow/jsonpath)[ RSS](/packages/flow-jsonpath/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (2)Versions (19)Used By (20)

❗ New project maintainers ❗
===========================

[](#exclamation-new-project-maintainers-exclamation)

This project is no longer maintained here. Please go to .

JSONPath [![Build Status](https://camo.githubusercontent.com/d725fcee112b0044f760ccf4ea09b4f7d2cc7eff2a5fd9e25177fa31b59028e8/68747470733a2f2f7472617669732d63692e6f72672f466c6f77436f6d6d756e69636174696f6e732f4a534f4e506174682e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/FlowCommunications/JSONPath)
=========================================================================================================================================================================================================================================================================================================================

[](#jsonpath-)

This is a [JSONPath](http://goessner.net/articles/JsonPath/) implementation for PHP based on Stefan Goessner's JSONPath script.

JSONPath is an XPath-like expression language for filtering, flattening and extracting data.

This project aims to be a clean and simple implementation with the following goals:

- Object-oriented code (should be easier to manage or extend in future)
- Expressions are parsed into tokens using code inspired by the Doctrine Lexer. The tokens are cached internally to avoid re-parsing the expressions.
- There is no `eval()` in use
- Any combination of objects/arrays/ArrayAccess-objects can be used as the data input which is great if you're de-serializing JSON in to objects or if you want to process your own data structures.

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

[](#installation)

**PHP 7.1+**

```
composer require flow/jsonpath
```

**PHP 5.4 - 5.6**

Support for PHP 5.x is deprecated... the current version should work but all unit tests are run against 7.1+ and support may be dropped at any time in the future.

A legacy branch is maintained in `php-5.x` and can be composer-installed as follows: `"flow/jsonpath": "dev-php-5.x"`

JSONPath Examples
-----------------

[](#jsonpath-examples)

JSONPathResult`$.store.books[*].author`the authors of all books in the store`$..author`all authors`$.store..price`the price of everything in the store.`$..books[2]`the third book`$..books[(@.length-1)]`the last book in order.`$..books[-1:]`the last book in order.`$..books[0,1]`the first two books`$..books[:2]`the first two books`$..books[::2]`every second book starting from first one`$..books[1:6:3]`every third book starting from 1 till 6`$..books[?(@.isbn)]`filter all books with isbn number`$..books[?(@.price [['name' => 'Joe'], ['name' => 'Jane'], ['name' => 'John']]];
$result = (new JSONPath($data))->find('$.people.*.name'); // returns new JSONPath
// $result[0] === 'Joe'
// $result[1] === 'Jane'
// $result[2] === 'John'
```

### Magic method access

[](#magic-method-access)

The options flag `JSONPath::ALLOW_MAGIC` will instruct JSONPath when retrieving a value to first check if an object has a magic `__get()` method and will call this method if available. This feature is *iffy* and not very predictable as:

- wildcard and recursive features will only look at public properties and can't smell which properties are magically accessible
- there is no `property_exists` check for magic methods so an object with a magic `__get()` will always return `true` when checking if the property exists
- any errors thrown or unpredictable behaviour caused by fetching via `__get()` is your own problem to deal with

```
$jsonPath = new JSONPath($myObject, JSONPath::ALLOW_MAGIC);
```

For more examples, check the JSONPathTest.php tests file.

Script expressions
------------------

[](#script-expressions)

Script expressions are not supported as the original author intended because:

- This would only be achievable through `eval` (boo).
- Using the script engine from different languages defeats the purpose of having a single expression evaluate the same way in different languages which seems like a bit of a flaw if you're creating an abstract expression syntax.

So here are the types of query expressions that are supported:

```
[?(@._KEY_ _OPERATOR_ _VALUE_)] // , !=, and ==
Eg.
[?(@.title == "A string")] //
[?(@.title = "A string")]
// A single equals is not an assignment but the SQL-style of '=='

```

Known issues
------------

[](#known-issues)

- This project has not implemented multiple string indexes eg. `$[name,year]` or `$["name","year"]`. I have no ETA on that feature and it would require some re-writing of the parser that uses a very basic regex implementation.

Similar projects
----------------

[](#similar-projects)

[Galbar/JsonPath-PHP](https://github.com/Galbar/JsonPath-PHP) is a PHP implementation that does a few things this project doesn't and is a strong alternative

[JMESPath](https://github.com/jmespath) does similiar things, is full of features and has a PHP implementation

The [Hash](http://book.cakephp.org/2.0/en/core-utility-libraries/hash.html) utility from CakePHP does some similar things

The original JsonPath implementations is available at http://code.google.com/p/jsonpath and re-hosted for composer here [Peekmo/JsonPath](https://github.com/Peekmo/JsonPath).

[ObjectPath](http://objectpath.org) (https://github.com/adriank/ObjectPath) appears to be a Python/JS implementation with a new name and extra features.

Changelog
---------

[](#changelog)

### 0.5.0

[](#050)

- Fixed the slice notation (eg. \[0:2:5\] etc.). **Breaks code relying on the broken implementation**

### 0.3.0

[](#030)

- Added JSONPathToken class as value object
- Lexer clean up and refactor
- Updated the lexing and filtering of the recursive token ("..") to allow for a combination of recursion and filters, eg. $..\[?(@.type == 'suburb')\].name

### 0.2.1 - 0.2.5

[](#021---025)

- Various bug fixes and clean up

### 0.2.0

[](#020)

- Added a heap of array access features for more creative iterating and chaining possibilities

### 0.1.x

[](#01x)

- Init

###  Health Score

47

—

FairBetter than 94% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity65

Solid adoption and visibility

Community37

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 79.7% 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 ~136 days

Recently: every ~260 days

Total

14

Last Release

2499d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/82c5de45afd4f3157345b31b87f2953732fd094c7a002f2e968285724d35809c?d=identicon)[stephenfrank](/maintainers/stephenfrank)

---

Top Contributors

[![stephenfrank](https://avatars.githubusercontent.com/u/112059?v=4)](https://github.com/stephenfrank "stephenfrank (47 commits)")[![oleg-andreyev](https://avatars.githubusercontent.com/u/1244112?v=4)](https://github.com/oleg-andreyev "oleg-andreyev (6 commits)")[![simonberger](https://avatars.githubusercontent.com/u/7163526?v=4)](https://github.com/simonberger "simonberger (2 commits)")[![flowcomm](https://avatars.githubusercontent.com/u/95018?v=4)](https://github.com/flowcomm "flowcomm (1 commits)")[![martinssipenko](https://avatars.githubusercontent.com/u/598744?v=4)](https://github.com/martinssipenko "martinssipenko (1 commits)")[![ThomasLandauer](https://avatars.githubusercontent.com/u/1054469?v=4)](https://github.com/ThomasLandauer "ThomasLandauer (1 commits)")[![twistor](https://avatars.githubusercontent.com/u/42400?v=4)](https://github.com/twistor "twistor (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[masterminds/html5

An HTML5 parser and serializer.

1.8k242.8M229](/packages/masterminds-html5)[sabberworm/php-css-parser

Parser for CSS Files written in PHP

1.8k191.2M65](/packages/sabberworm-php-css-parser)[jms/metadata

Class/method/property metadata management in PHP

1.8k152.8M88](/packages/jms-metadata)[jms/serializer-bundle

Allows you to easily serialize, and deserialize data of any complexity

1.8k89.3M627](/packages/jms-serializer-bundle)[hassankhan/config

Lightweight configuration file loader that supports PHP, INI, XML, JSON, and YAML files

97513.5M170](/packages/hassankhan-config)[meyfa/php-svg

Read, edit, write, and render SVG files with PHP

54613.9M42](/packages/meyfa-php-svg)

PHPackages © 2026

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