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

keeping hierarchical structure? #97

Closed bsdis closed 11 months ago

bsdis commented 2 years ago

Hello, Why does this:

[
    m.value
    for m in jp.parse("$.*.[fe].[*].n,v").find(
        {
            "1": {"fe": [{"n": "a", "v": "b"}, {"n": "c", "v": "d"}]},
            "2": {"fe": [{"n": "e", "v": "f"}, {"n": "g", "v": "h"}]},
        }
    )
]

give ["a", "b", "c", "d", "e", "f", "g", "h"] ?

I was expecting it to give: [(("a", "b"), ("c", "d")), (("e", "f"), ("g", "h"))]

It seems like the hierarchical structure gets dropped. Why?

michaelmior commented 11 months ago

When using , in a path, it's effectively treated as two separate paths and when you go through the results, you'll get the result of querying each path independently. If you want to keep that structure, you can always group by the parent path.