Skip to content

Add Input::pointers() to iterate over JSON pointers#20

Open
thekid wants to merge 4 commits intomasterfrom
feature/pointers
Open

Add Input::pointers() to iterate over JSON pointers#20
thekid wants to merge 4 commits intomasterfrom
feature/pointers

Conversation

@thekid
Copy link
Copy Markdown
Member

@thekid thekid commented Apr 3, 2026

This pull request adds pointers() complementing the pairs() and elements() iterations. This makes it possible to stream values even when the data contains a wrapper, such as the data key often seen in REST APIs.

Example

Input data:

{
  "data": [
    "string 1",
    "string 2",
    "string 3",
    // ...
  ]
}

Processing:

use io\streams\FileInputStream;
use text\json\StreamInput;

$input= new StreamInput(new FileInputStream($argv[1]));
foreach ($input->pointers() as $pointer => $value) {
  if (str_starts_with($pointer, '/data/')) {
    echo $pointer, ' => ', $value, "\n";
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant