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

Wrong datum and value returned by find method #96

Open M-Ghasemi opened 2 years ago

M-Ghasemi commented 2 years ago

I think a.[0].[0] and a.[1].[0] should not be part of the results and their value should not be as it is.

import jsonpath_ng
print('VERSION: ' + jsonpath_ng.__version__)
data = {'a': ['foo', 'bar']}
for datum in jsonpath_ng.parse('$..[*]').find(data):
    print(f"\npath: {datum.full_path} | value: {datum.value}")

    try:
        equivalent_datum = jsonpath_ng.parse(str(datum.full_path)).find(data)[0]
        if equivalent_datum.value != datum.value:
            print(f"THE CORRECT VALUE IS: {equivalent_datum.value}")
    except KeyError:
        pass
VERSION: 1.5.3

path: [0] | value: {'a': ['foo', 'bar']}

path: a.[0] | value: foo

path: a.[1] | value: bar

path: a.[0].[0] | value: foo
THE CORRECT VALUE IS: f

path: a.[1].[0] | value: bar
THE CORRECT VALUE IS: b