Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there a way to get the map result with 'relative path' like *..c ? #74

Closed
ClericPy opened this issue Mar 8, 2020 · 5 comments
Closed

Comments

@ClericPy
Copy link

ClericPy commented Mar 8, 2020

input:
{"a": {"b": {"c": {"d": "value"}}}}
path:
*..c
expect:
{"d": "value"}

@darrenmothersele
Copy link

This works for the example you've given...

values(@)[0].values(@)[0].values(@)[0]

@ClericPy
Copy link
Author

This works for the example you've given...

values(@)[0].values(@)[0].values(@)[0]

Thanks for answering, but the relative path means that I don't know how many blocks in the given nested dict, so I wonder if there is a way to do like the objectpath do.

import objectpath

raw = {
    "args": {},
    "headers": {
        "Accept": "*/*",
        "Accept-Encoding": "gzip, deflate",
        "Host": "httpbin.org",
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36",
        "X-Amzn-Trace-Id": "Root=1-5e67a051-171e2874180dc5964fb7884d"
    },
    "origin": "47.104.199.113",
    "url": "http://httpbin.org/get"
}
tree = objectpath.Tree(raw)
result = [i for i in tree.execute('$..Accept')]
print(result)
# ['*/*']

@darrenmothersele
Copy link

Ah, I see. As far as I know, recursive descent is not possible in JMESPath

@ClericPy
Copy link
Author

@darrenmothersele

Yes, I read the doc/source code in a while but not found that feature, so it may not be the purpose of JMESPath.

JMESPath is very fast, and the implementation didn't contains a recursive parsing usage, this issue is just want to ensure that.

Close issue, thank all the same.

@springcomp
Copy link
Contributor

@ClericPy We want to propose this feature to JMESPath and will include this in the next iteration for JMESPath Community.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants