stream-parser icon indicating copy to clipboard operation
stream-parser copied to clipboard

Start reading from a specific node in the json

Open markdza opened this issue 6 years ago • 2 comments

How do you say you want to go a specific node in the json to begin parsing? For e.g. in the example json file below, I want it to only read the data array

{
  "headers": {
    "col1": "id1",
    "col1": "id2",
  },
  "data": [
    {
      "name": "John"
    },
    {
      "name": "Julie"
    }
  ]
}

If I do something like this it starts reading from the very beginning of the json and throws an error

$filename = 'abc.json';
StreamParser::json(storage_path($filename))->each(function(Collection $record){
    dd($record);
});

Can they be an implementation to do something like this (so it starts reading only data)?

$filename = 'abc.json';
StreamParser::json(storage_path($filename), 'data')->each(function(Collection $record){
    dd($record);
});

markdza avatar Mar 27 '19 19:03 markdza

anything here?

ideea avatar Sep 02 '22 09:09 ideea

PRs are highly welcomed

sergiorodenas avatar Sep 02 '22 13:09 sergiorodenas