h2non / jsonpath-ng

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

unexpected result with child-selector and multiple fields #51

Open wfehr opened 4 years ago

wfehr commented 4 years ago

The path id,name,child.[*].id will only return the value of child.[*].id and id,name is ignored.

Example code to reproduce:

from jsonpath_ng import parse

data = {'id': 'foo', 'name': 'Foo', 'child': [{'id': 'child-foo'}]}

cases = (
    ('id,name', ['foo', 'Foo']),
    ('id,name,child.[*]', ['foo', 'Foo', {'id': 'child-foo'}]),
    ('id,name,child.[*].id', ['foo', 'Foo', 'child-foo']),  # Error
)

for path, expected in cases:
    actual = [m.value for m in parse(path).find(data)]
    if expected != actual:
        print('parser: ' + path)
        print('actual: ' + str(actual))
        print('expected: ' + str(expected))

# prints out:
# parser: id,name,child.[*].id
# actual: ['child-foo']
# expected: ['foo', 'Foo', 'child-foo']