Hi,There is an xml module (https://docs.ansible.com/ansible/2.4/xml_module.html) that would allow you to extract elements of the target and output them through a Json filter however without further logical manipulation you will just end up with a list of all elements.
You have several ways to create data structures (persistent variables) within the Ansible code itself which would solve the problem of the single long list of elements. Push the variables through a json filter and it solves the problem problem of actually using json to format data intelligent, which only leaves correctly creating/populating the data structures in the Ansible code as an outstanding issue.
Hope that is of some assistance.
Thanks.
Is there a filter or any work around to convert an XML to JSON using ansible?
Thank you very much for the response. First let me explain what I'm trying to do here and then what I have done so far.
I'm trying to call and rest api which I'm using URI module to do that. Success response of this api returns a xml response not json. But my end user needs the output from my ansible playbook to be json so others can consume it for other processes. This xml response comes in the content of the response. E.g. return_content : yes . So this content is a string which is in xml format. I need to sanitize it to remove characters like \n (new line). That's been done using regex_replace. So then we get the plain xml. Now this xml output needs to be shown in json manner.
What i have been thinking and trying to do so far is create a python scrip which does the job. Then call the method in python script as a filter e.g. "{{ xml_response | xml_to_json}}". But stucked here on implementing this. Are there any easier work around for this?
--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscribe@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/4d0c1c1f-ca37-49b4-9402-b73ff9f1db28%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/4d2a1316-e4bb-4447-b84a-4df5a518d30f%40googlegroups.com.