Hi,

THe quickest way is to create your own filter:

1. Create a 'filter_plugins' directory (in the same directory as you
playbook or roles).
2. Create a xml2json.py file in that directory with the following content:

############## cut below

class FilterModule(object):

    def filters(self):
        return {
            'xml2json': self.xml2json,
        }

    def xml2json(self, value):
        import xmltodict, json
        return json.dumps(xmltodict.parse(value))

############# cut above

Once its there - you can call the filter:

set_fact:
 content_json: "{{ content_xml | xml2json }}"

You can obviously also call this 'in place' as any other filter.

kind regards
Pshem


On Tue, 8 May 2018 at 23:44 Madushan Chathuranga <[email protected]>
wrote:

> Hi,
>
> Is there a filter or any work around to convert an XML to JSON using
> ansible?
>
> Thanks.
>
> --
> 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 [email protected].
> To post to this group, send email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/4d2a1316-e4bb-4447-b84a-4df5a518d30f%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/4d2a1316-e4bb-4447-b84a-4df5a518d30f%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> 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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAEaZiRW%2B1SQDaPXG%3DR4EQqf-qZ%3DU_nk%2BLkMO_GpC%2BvpDVy3xPw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to