{"id":16438920,"url":"https://github.com/craigh411/jmespathiterator","last_synced_at":"2025-10-09T16:07:58.650Z","repository":{"id":56958668,"uuid":"338031754","full_name":"craigh411/JmespathIterator","owner":"craigh411","description":"⚡️ Access a PHP array using JMESPath","archived":false,"fork":false,"pushed_at":"2021-02-11T17:15:28.000Z","size":32,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-09T16:07:58.236Z","etag":null,"topics":["arrays","jmespath","php"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/craigh411.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-02-11T13:08:03.000Z","updated_at":"2021-02-11T19:36:02.000Z","dependencies_parsed_at":"2022-08-21T04:40:23.342Z","dependency_job_id":null,"html_url":"https://github.com/craigh411/JmespathIterator","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/craigh411/JmespathIterator","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/craigh411%2FJmespathIterator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/craigh411%2FJmespathIterator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/craigh411%2FJmespathIterator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/craigh411%2FJmespathIterator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/craigh411","download_url":"https://codeload.github.com/craigh411/JmespathIterator/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/craigh411%2FJmespathIterator/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279001762,"owners_count":26083171,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-09T02:00:07.460Z","response_time":59,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["arrays","jmespath","php"],"created_at":"2024-10-11T09:07:02.930Z","updated_at":"2025-10-09T16:07:58.633Z","avatar_url":"https://github.com/craigh411.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# JmespathIterator\n\n`JmespathIterator` allows you to access a PHP array using [JMESPath](https://jmespath.org/) just like you would a standard array.\n\n## Install\n\nYou can install JmespathIterator via composer:\n\n`composer require craigh/jmespath-iterator`\n\n## Usage\n\nCreate a new `JmespathIterator` object, then pass the JMESPath expression as the array key:\n\n### Basic Example\n\n```php\n\nuse Humps\\Jmespath\\JmespathIterator;\n\n$iterator = new JmespathIterator([\n  'foo' =\u003e [\n    'bar' =\u003e [\n      'baz' =\u003e 'qux',\n    ],\n  ],\n]);\n\necho $iterator['foo.bar.baz']; // output: 'qux'\n```\n\n### List Projection Example\n\n```php\nuse Humps\\Jmespath\\JmespathIterator;\n\n$iterator = new JmespathIterator([\n  'people' =\u003e\n    [\n      [\n        'first' =\u003e 'James',\n        'last' =\u003e 'd',\n      ],\n      [\n        'first' =\u003e 'Jacob',\n        'last' =\u003e 'e',\n      ],\n      [\n        'first' =\u003e 'Jayden',\n        'last' =\u003e 'f',\n      ],\n      [\n        'missing' =\u003e 'different',\n       ],\n    ],\n    'foo' =\u003e\n      [\n        'bar' =\u003e 'baz',\n      ],\n]);\n\nvar_dump($iterator['people[*].first']); // output: [\"James\", \"Jacob\", \"Jayden\"]\n        \n```\n\n### Every Level is a JmespathIterator\n\n`JmespathIterator` always returns arrays as `JmespathIterator` objects, which means you can query nested arrays using JMESPath:\n\n\n```php\nuse Humps\\Jmespath\\JmespathIterator;\n\n$iterator = new JmespathIterator([\n  [\n    'foo' =\u003e [\n      'bar' =\u003e 'qux',\n    ],\n  ],\n]);\n\necho $iterator[0]['foo.bar']; // output: 'qux'\n```\n\nAnd iterate over it just like a standard array:\n\n```php\nuse Humps\\Jmespath\\JmespathIterator;\n\n$iterator = new JmespathIterator([\n  [\n    'bar' =\u003e [\n      'baz' =\u003e 'qux',\n    ],\n  ],\n  [\n    'bar' =\u003e [\n      'baz' =\u003e 'qux',\n    ],\n  ],\n]);\n\nif(count($iterator)){\n  foreach ($iterator as $value) {\n    echo $value['bar.baz'];\n  }\n}\n```\n\n### Add Items like An Array\n\n`JmespathIterator` implements the `ArrayAccess` interface, so you can add array values just as you usually would:\n\n```php\nuse Humps\\Jmespath\\JmespathIterator;\n\n$iterator = new JmespathIterator();\n$iterator[] = 'foo';\n$iterator[] = 'bar';\n\necho $iterator[1] // output: 'bar';\n```\n\n### Slicing\n\nTo make things cleaner, you don't need to wrap slice expressions in square brackets, but you can if you want:\n\n```php\nuse Humps\\Jmespath\\JmespathIterator;\n\n$iterator = new JmespathIterator(['foo','bar','baz','qux', 'qux']);\n\nvar_dump($iterator['0::2']); // outputs: ['foo', 'baz', 'qux']\nvar_dump($iterator['[0::2]']); // outputs: ['foo', 'baz', 'qux']\n```\n\n### Remember: It's Not Actually An Array!\n\n\nWhile a `JmespathIterator` object might feel like an array, it's not; but if you need it to be you can use the `toArray()` method:\n\n```php\nuse Humps\\Jmespath\\JmespathIterator;\n\n$iterator = new JmespathIterator(['foo','bar','baz','qux', 'quxx']);\n$array = $iterator-\u003etoArray();\nnatsort($array);\n$newIterator = new JmespathIterator($array); \nvar_dump($newIterator); // outputs: ['bar', 'baz','foo', 'qux', 'quxx']\n```\n\n\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcraigh411%2Fjmespathiterator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcraigh411%2Fjmespathiterator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcraigh411%2Fjmespathiterator/lists"}