json-machine
json-machine copied to clipboard
Wrong key when combining list and scalar value pointers
When combining a pointer to a list and a pointer to a scalar value, and the scalar is after the list (does not happen when scalar before list!), then the key of the scalar is not correct.
Example:
$response = '{
"items": [
{
"item_id": 1,
"external_id": "some id 1"
},
{
"item_id": 2,
"external_id": "some id 2"
}
],
"total": 2
}';
$json = Items::fromString($response, ['pointer' => ['/items', '/total']]);
foreach ($json as $key => $value) {
echo "key=" . $key . "\n";
}
This outputs:
key=0
key=1
key=2
Expected/correct output would be:
key=0
key=1
key=total
Hi, thanks for reaching out, and sorry for the delay. I had much stuff going on in life 😄. I'll try looking into it soon. Thanks