-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
json_query filter fails when using the functions "contains", "starts_with", others #320
Comments
Files identified in the description: If these files are inaccurate, please update the |
Files identified in the description: If these files are inaccurate, please update the |
Use the following to convert the data properly for now. I think the issue comes from the way ansible manages the JSON files. - debug:
var: item
with_items: "{{ json_file.results | to_json | from_json | json_query(jq_old) }}"
- debug:
var: item
with_items: "{{ json_file.results | to_json | from_json | json_query(jq_new) }}" The plugin just opens the result and parses with jmespath. When doing the same with Python directly, something like: import json
import jmespath
expr = "results[?contains(interface.name,'1114')]"
openrojson = open("results.json", "r")
data = json.loads(openrojson.read())
outputorig = jmespath.search(expr, data) It works fine. IMHO, this issue is more related to Ansible Core than the |
Thank you for workaround. I'd love to see this workaround described in the module documentation, since this issue is pretty old and going to stay for a while. Unless you have a fix to merge soon, of course. |
It looks like maintenance as restarted on jmespath side and the author actually asked a question on the corresponding related ticket. This has drifted a lot so I'm not sure anyone implicated at start is still following this. Meanwhile, looks like we have an open window to get this fixed. Is someone still activelly following this issue ? |
I am following jmespath/jmespath.py#158 and #320, and would love to see it fixed eventually. I'm sure I'm not the only one. |
* Add a note about - data structure returned from register variables needs to be parsed using ``to_json | from_json`` in order to get correct result. * Add examples for starts_with and contains Fixes: ansible-collections/community.general#320 Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
I added documentation around this in PR ansible/ansible#72821. Please feel free to comment. |
resolved_by_pr ansible/ansible#72821 |
jmespath library does not undestand custom string types such as AnsibleUnicode, and AnsibleUnsafeText. So user need to use ``to_json | from_json`` filter while using functions like ``starts_with`` and ``contains`` etc. This hack will allow user to get rid of this filter. Fixes: ansible-collections#320 Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
jmespath library does not undestand custom string types such as AnsibleUnicode, and AnsibleUnsafeText. So user need to use ``to_json | from_json`` filter while using functions like ``starts_with`` and ``contains`` etc. This hack will allow user to get rid of this filter. Fixes: #320 Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
jmespath library does not undestand custom string types such as AnsibleUnicode, and AnsibleUnsafeText. So user need to use ``to_json | from_json`` filter while using functions like ``starts_with`` and ``contains`` etc. This hack will allow user to get rid of this filter. Fixes: #320 Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com> (cherry picked from commit 5319437)
jmespath library does not undestand custom string types such as AnsibleUnicode, and AnsibleUnsafeText. So user need to use ``to_json | from_json`` filter while using functions like ``starts_with`` and ``contains`` etc. This hack will allow user to get rid of this filter. Fixes: #320 Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com> (cherry picked from commit 5319437) Co-authored-by: Abhijeet Kasurde <akasurde@redhat.com>
SUMMARY
This issue is migrated from ansible/ansible#27299
When using the
json_query
filter with the query[?interface.name=='irb.1111'].{interface: interface.name, address: address}
everything functions fine and I get the correct results back. When that filter is changed to[?contains(interface.name,'irb')].{interface: interface.name, address: address}
traceback errors withjmespath/functions.py
start occurring that complain about invalid type for value.ISSUE TYPE
COMPONENT NAME
json_query
ANSIBLE VERSION
CONFIGURATION
Standard
OS / ENVIRONMENT
N/A
STEPS TO REPRODUCE
EXPECTED RESULTS
ACTUAL RESULTS
The text was updated successfully, but these errors were encountered: