h2non / jsonpath-ng

Finally, a JSONPath implementation for Python that aims to be standard compliant. That's all. Enjoy!
Apache License 2.0
572 stars 85 forks source link

Feature request #79

Open nivesnine opened 3 years ago

nivesnine commented 3 years ago

Looking for a way to compare current object to another object:

$.objects[1].some_other_thing[?(@.some_field != $.objects[0].some_thing.some_field)]

it would also be nice to be able to compare arrays, if that's at all possible:

$.objects[?(@.some_other_thing != @.some_thing)].some_field

Example where some_field is different:

[ { "objects": [ { "some_thing": { "some_field": 1 } }, { "some_thing": { "some_field": 2 } } ] } ]

Result:

'some_field': 1, 'some_field': 2

Example where some_field is the same:

[ { "objects": [ { "some_thing": { "some_field": 1 } }, { "some_other_thing": { "some_field": 1 } } ] } ]

Result:

'some_field': 1,

This may be out of the scope of this project, or it's possible there's already a way to do this. Attempting to try this caused errors around $ and @ in the filter after the !=:

$.objects[1].some_other_thing[?(@.some_field != $.objects[0].some_thing.some_field)]

and

$.objects[?(@.some_other_thing != @.some_thing)].some_field