PHPackages                             craigh/jmespath-iterator - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. craigh/jmespath-iterator

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

craigh/jmespath-iterator
========================

Access a PHP array using Jmespath just like you would a standard array

v1.0.1(5y ago)023MITPHP

Since Feb 11Pushed 5y ago1 watchersCompare

[ Source](https://github.com/craigh411/JmespathIterator)[ Packagist](https://packagist.org/packages/craigh/jmespath-iterator)[ RSS](/packages/craigh-jmespath-iterator/feed)WikiDiscussions main Synced 6d ago

READMEChangelog (1)Dependencies (2)Versions (3)Used By (0)

JmespathIterator
================

[](#jmespathiterator)

`JmespathIterator` allows you to access a PHP array using [JMESPath](https://jmespath.org/) just like you would a standard array.

Install
-------

[](#install)

You can install JmespathIterator via composer:

`composer require craigh/jmespath-iterator`

Usage
-----

[](#usage)

Create a new `JmespathIterator` object, then pass the JMESPath expression as the array key:

### Basic Example

[](#basic-example)

```
use Humps\Jmespath\JmespathIterator;

$iterator = new JmespathIterator([
  'foo' => [
    'bar' => [
      'baz' => 'qux',
    ],
  ],
]);

echo $iterator['foo.bar.baz']; // output: 'qux'
```

### List Projection Example

[](#list-projection-example)

```
use Humps\Jmespath\JmespathIterator;

$iterator = new JmespathIterator([
  'people' =>
    [
      [
        'first' => 'James',
        'last' => 'd',
      ],
      [
        'first' => 'Jacob',
        'last' => 'e',
      ],
      [
        'first' => 'Jayden',
        'last' => 'f',
      ],
      [
        'missing' => 'different',
       ],
    ],
    'foo' =>
      [
        'bar' => 'baz',
      ],
]);

var_dump($iterator['people[*].first']); // output: ["James", "Jacob", "Jayden"]

```

### Every Level is a JmespathIterator

[](#every-level-is-a-jmespathiterator)

`JmespathIterator` always returns arrays as `JmespathIterator` objects, which means you can query nested arrays using JMESPath:

```
use Humps\Jmespath\JmespathIterator;

$iterator = new JmespathIterator([
  [
    'foo' => [
      'bar' => 'qux',
    ],
  ],
]);

echo $iterator[0]['foo.bar']; // output: 'qux'
```

And iterate over it just like a standard array:

```
use Humps\Jmespath\JmespathIterator;

$iterator = new JmespathIterator([
  [
    'bar' => [
      'baz' => 'qux',
    ],
  ],
  [
    'bar' => [
      'baz' => 'qux',
    ],
  ],
]);

if(count($iterator)){
  foreach ($iterator as $value) {
    echo $value['bar.baz'];
  }
}
```

### Add Items like An Array

[](#add-items-like-an-array)

`JmespathIterator` implements the `ArrayAccess` interface, so you can add array values just as you usually would:

```
use Humps\Jmespath\JmespathIterator;

$iterator = new JmespathIterator();
$iterator[] = 'foo';
$iterator[] = 'bar';

echo $iterator[1] // output: 'bar';
```

### Slicing

[](#slicing)

To make things cleaner, you don't need to wrap slice expressions in square brackets, but you can if you want:

```
use Humps\Jmespath\JmespathIterator;

$iterator = new JmespathIterator(['foo','bar','baz','qux', 'qux']);

var_dump($iterator['0::2']); // outputs: ['foo', 'baz', 'qux']
var_dump($iterator['[0::2]']); // outputs: ['foo', 'baz', 'qux']
```

### Remember: It's Not Actually An Array!

[](#remember-its-not-actually-an-array)

While a `JmespathIterator` object might feel like an array, it's not; but if you need it to be you can use the `toArray()` method:

```
use Humps\Jmespath\JmespathIterator;

$iterator = new JmespathIterator(['foo','bar','baz','qux', 'quxx']);
$array = $iterator->toArray();
natsort($array);
$newIterator = new JmespathIterator($array);
var_dump($newIterator); // outputs: ['bar', 'baz','foo', 'qux', 'quxx']
```

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 61.1% 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 ~0 days

Total

2

Last Release

1921d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/791b31f6b625d43874f70831846b002b7bb46dc911e38b02250e7aaab6596716?d=identicon)[craigh411](/maintainers/craigh411)

---

Top Contributors

[![craigh411](https://avatars.githubusercontent.com/u/13747552?v=4)](https://github.com/craigh411 "craigh411 (11 commits)")[![CraigGoesCoding](https://avatars.githubusercontent.com/u/70750632?v=4)](https://github.com/CraigGoesCoding "CraigGoesCoding (7 commits)")

---

Tags

arraysjmespathphp

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/craigh-jmespath-iterator/health.svg)

```
[![Health](https://phpackages.com/badges/craigh-jmespath-iterator/health.svg)](https://phpackages.com/packages/craigh-jmespath-iterator)
```

###  Alternatives

[pimcore/data-importer

Adds a comprehensive import functionality to Pimcore Datahub

44763.4k2](/packages/pimcore-data-importer)[honeybee/honeybee

Library for implementing CQRS driven, event-sourced and distributed architectures.

222.1k4](/packages/honeybee-honeybee)[graste/params

Array wrapper that eases the retrieval of values. Has parameters, options and settings and traits for inclusion in other libraries.

107.0k](/packages/graste-params)

PHPackages © 2026

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