json-machine icon indicating copy to clipboard operation
json-machine copied to clipboard

Wrong key when combining list and scalar value pointers

Open daniel-sc opened this issue 1 year ago • 1 comments

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

daniel-sc avatar Feb 21 '24 11:02 daniel-sc

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

halaxa avatar Jul 11 '24 10:07 halaxa