jsonpath icon indicating copy to clipboard operation
jsonpath copied to clipboard

Duplicate results no filter

Open gkorland opened this issue 3 years ago • 1 comments

Filter might return duplicate results when the internal objects are similar.

e.g. input JSON both objects have name == {"first":"A","middle":"A"}

[{{"name":{"first":"A","middle":"A"},"rank":8},{"name":{"first":"A","middle":"A"},"rank":90}]

When running:

$[?($.name.first=="A")]

The following result is returned:

[{{"name":{"first":"A","middle":"A"},"rank":8},{"name":{"first":"A","middle":"A"},"rank":8},{{"name":{"first":"A","middle":"A"},"rank":90},{"name":{"first":"A","middle":"A"},"rank":90}]

It seems like the bug is in this code which compares all the candidates with all values and return each "parent" twice. https://github.com/freestrings/jsonpath/blob/1a84c5af9445e617a6deed14dadfaee13af0d95f/src/select/expr_term.rs#L107

ref https://github.com/RedisJSON/RedisJSON/issues/667

gkorland avatar Mar 14 '22 13:03 gkorland

Here's a working example (above syntax is broken):

[{"name":{"first":"A"},"rank":8},{"name":{"first":"A"},"rank":90}]

for selector

$[?(@.name.first=="A")]

Interestingly enough a simpler document works:

[{"name": "A","rank":8},{"name": "A","rank":90}]

$[?(@.name=="A")]

cburgmer avatar Mar 09 '23 08:03 cburgmer