Skip to content
This repository has been archived by the owner on Oct 14, 2020. It is now read-only.

Issue filtering with @ #49

Open
lookitsjonno opened this issue Dec 19, 2019 · 3 comments
Open

Issue filtering with @ #49

lookitsjonno opened this issue Dec 19, 2019 · 3 comments

Comments

@lookitsjonno
Copy link

lookitsjonno commented Dec 19, 2019

Apologies in advance, I'm new to JSONPath.

I do not understand why I am not able to filter based on keys, but a wildcard works. For example:

$content = [
    'body' => [
        'order' => [
            'id' => 2
        ]
    ]
];
// doesn't find the element
var_dump((new JSONPath($content))->find('$.body.order[?(@.id == "2")]'));
// finds the element
var_dump((new JSONPath($content))->find('$..[?(@.id == "2")]'));
@cburgmer
Copy link

cburgmer commented Feb 6, 2020

This looks like an interesting case:

IMHO [] makes sense for $.body.order[?(@.id==2)] on {"body": {"order": {"id": 2}}} as $.body.order matches an object (not a list of objects), and thus the filter would operate on the value.

Compare to {"body": {"order": [{"id": 2}]}} (note the additional []).

$..[?(@.id==2)] however operates on a list of candidates produced by the recursive decent.

This explanation is given from a perspective of the internal implementation. The original post from Goessner probably does not capture that.

I've taken the liberty and added this as a test case to the comparison project: https://cburgmer.github.io/json-path-comparison/#filter_equal_on_object_with_key_matching_query (do scroll a bit to see the highlighted row). You can compare the responses from the different implementations. They don't currently agree.

@cburgmer
Copy link

cburgmer commented Feb 6, 2020

On the side, implementations also don't agree on trying to match "2" for 2 and 2 for "2":
https://cburgmer.github.io/json-path-comparison/#filter_equal_on_number_value_with_string_query and https://cburgmer.github.io/json-path-comparison/#filter_equal_on_string_value_with_number_query. This implementation here is on the generous side.

@martinssipenko
Copy link
Contributor

This project is now marked as abandoned and suggests using softcreatr/jsonpath as a replacement. If you think this issue is still relevant please open a new ticket under the new project.

https://github.com/SoftCreatR/JSONPath

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants