PHPackages                             ropi/json-path-evaluator - 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. ropi/json-path-evaluator

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

ropi/json-path-evaluator
========================

A JSONPath implementation for PHP

v1.1.0(2y ago)094MITPHPPHP &gt;=8.1.0

Since Dec 16Pushed 2y ago1 watchersCompare

[ Source](https://github.com/ro-pi/json-path-evaluator)[ Packagist](https://packagist.org/packages/ropi/json-path-evaluator)[ RSS](/packages/ropi-json-path-evaluator/feed)WikiDiscussions main Synced today

READMEChangelog (4)Dependencies (2)Versions (5)Used By (0)

A JSONPath evaluator for PHP
============================

[](#a-jsonpath-evaluator-for-php)

This library is a PHP based implementation of JSONPath ([RFC 9535](https://datatracker.ietf.org/doc/rfc9535/)).

It allows to evaluate JSONPath expressions directly on PHP objects and/or arrays.
This implementation passes all compliance tests of [JSONPath Compliance Test Suite](https://github.com/jsonpath-standard/jsonpath-compliance-test-suite).

Requirements
------------

[](#requirements)

- PHP &gt;= 8.1
- ext-ctype
- ext-intl
- ext-mbstring

Table of contents
-----------------

[](#table-of-contents)

- [Installation](#installation)
- [Examples](#examples)
    - [Get values](#get-values)
    - [Get paths](#get-paths)
    - [Set values](#set-values)
    - [Set values and create non-existent paths](#set-values-and-create-non-existent-paths)
    - [Delete paths](#delete-paths)
    - [Custom function extensions](#custom-function-extensions)

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

[](#installation)

The library can be installed from a command line interface by using [composer](https://getcomposer.org/).

```
composer require ropi/json-path-evaluator

```

Examples
--------

[](#examples)

### Get values

[](#get-values)

The following example shows how to get values that match a JSONPath.
The result is always an array of values that match the JSONPath. If there are no matches, an empty array is returned.

```
$data = json_decode('{ "store": {
   "book": [
     { "category": "reference",
       "author": "Nigel Rees",
       "title": "Sayings of the Century",
       "price": 8.95
     },
     { "category": "fiction",
       "author": "Evelyn Waugh",
       "title": "Sword of Honour",
       "price": 12.99
     },
     { "category": "fiction",
       "author": "Herman Melville",
       "title": "Moby Dick",
       "isbn": "0-553-21311-3",
       "price": 8.99
     },
     { "category": "fiction",
       "author": "J. R. R. Tolkien",
       "title": "The Lord of the Rings",
       "isbn": "0-395-19395-8",
       "price": 22.99
     }
   ],
   "bicycle": {
     "color": "red",
     "price": 399
   }
 }
}');

$evaluator = new \Ropi\JsonPathEvaluator\JsonPathEvaluator();

$result = $evaluator->getValues($data, '$.store.book[*].author');
echo "Authors of all books in the store:\n" . json_encode($result, JSON_PRETTY_PRINT) . "\n";

$result = $evaluator->getValues($data, '$.store..price');
echo "Prices of everything in the store:\n" . json_encode($result, JSON_PRETTY_PRINT) . "\n";

$result = $evaluator->getValues($data, '$..book[-1]');
echo "Last book in order:\n" . json_encode($result, JSON_PRETTY_PRINT) . "\n";

$result = $evaluator->getValues($data, '$..book[0,1]');
echo "First two books with union operator:\n" . json_encode($result, JSON_PRETTY_PRINT) . "\n";

$result = $evaluator->getValues($data, '$..book[:2]');
echo "First two books with array slice operator:\n" . json_encode($result, JSON_PRETTY_PRINT) . "\n";

$result = $evaluator->getValues($data, '$..book[?@.isbn]');
echo "All books with an ISBN number:\n" . json_encode($result, JSON_PRETTY_PRINT) . "\n";

$result = $evaluator->getValues($data, '$..book[?@.price 9]');
echo "Deleted all $numDeleted books that are more expensive than 9:\n" . json_encode($data, JSON_PRETTY_PRINT) . "\n";
```

The above example will output:

```
Deleted all 2 books in store that are more expensive than 9:
{
    "store": {
        "book": {
            "0": {
                "category": "reference",
                "author": "Nigel Rees",
                "title": "Sayings of the Century",
                "price": 8.95
            },
            "2": {
                "category": "fiction",
                "author": "Herman Melville",
                "title": "Moby Dick",
                "isbn": "0-553-21311-3",
                "price": 8.99
            }
        },
        "bicycle": {
            "color": "red",
            "price": 399
        }
    }
}

```

### Custom function extensions

[](#custom-function-extensions)

The following example shows how to register custom function extensions according to section 2.4 of [RFC 9535](https://datatracker.ietf.org/doc/rfc9535/).

```
$evaluator = new \Ropi\JsonPathEvaluator\JsonPathEvaluator();

$data = json_decode('{
    "values": [
        {"property": "valueA"},
        {"property": "valueB"}
    ]
}');

$evaluator = new \Ropi\JsonPathEvaluator\JsonPathEvaluator();

$evaluator->registerFunction('myFunction', function(\Ropi\JsonPathEvaluator\Types\AbstractValueType $parameter1) {
    if (!$parameter1 instanceof \Ropi\JsonPathEvaluator\Types\JsonValue) {
        return new \Ropi\JsonPathEvaluator\Types\LogicalFalse();
    }

    return $parameter1->getValue() === 'valueB'
        ? new \Ropi\JsonPathEvaluator\Types\LogicalTrue()
        : new \Ropi\JsonPathEvaluator\Types\LogicalFalse();
});

$result = $evaluator->getValues($data, '$.values[?myFunction(@.property)].property');
echo json_encode($result, JSON_PRETTY_PRINT);
```

The above example will output:

```
[
    "valueB"
]

```

###  Health Score

25

—

LowBetter than 35% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~1 days

Total

4

Last Release

925d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/cd410511aaf1a75d11806f92a140ad8263bf46909be393cae9d4cdf4aabf8e4f?d=identicon)[ro-pi](/maintainers/ro-pi)

---

Top Contributors

[![ro-pi](https://avatars.githubusercontent.com/u/83430041?v=4)](https://github.com/ro-pi "ro-pi (22 commits)")

---

Tags

jsonjsonpathpathexpressionaccessorevaluator

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/ropi-json-path-evaluator/health.svg)

```
[![Health](https://phpackages.com/badges/ropi-json-path-evaluator/health.svg)](https://phpackages.com/packages/ropi-json-path-evaluator)
```

###  Alternatives

[mtdowling/jmespath.php

Declaratively specify how to extract elements from a JSON document

2.0k504.8M167](/packages/mtdowling-jmespathphp)[justinrainbow/json-schema

A library to validate a json schema.

3.6k334.7M788](/packages/justinrainbow-json-schema)[galbar/jsonpath

JSONPath implementation for querying and updating JSON objects

2087.1M126](/packages/galbar-jsonpath)[jms/serializer

Library for (de-)serializing data of any complexity; supports XML, and JSON.

2.3k141.9M929](/packages/jms-serializer)[jms/serializer-bundle

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

1.8k92.4M680](/packages/jms-serializer-bundle)[colinodell/json5

UTF-8 compatible JSON5 parser for PHP

30525.1M57](/packages/colinodell-json5)

PHPackages © 2026

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