# Filter plugin to convert executed command output to JSON

**URL:** <https://forum.ansible.com/t/filter-plugin-to-convert-executed-command-output-to-json/33522>\
**Category:** Ansible Developer\
**Created:** [July 30, 2020, 12:15am UTC](https://forum.ansible.com/t/filter-plugin-to-convert-executed-command-output-to-json/33522 "2020-07-30T00:15:40Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kelly\_Brazil](https://avatars.discourse-cdn.com/v4/letter/k/898d66/32.png) [@Kelly\_Brazil](https://forum.ansible.com/u/Kelly_Brazil)\
**Post date:** [July 30, 2020, 12:15am UTC](https://forum.ansible.com/t/filter-plugin-to-convert-executed-command-output-to-json/33522/1 "2020-07-30T00:15:40Z")

</div>

Hi everyone!

I’m not a day-to-day user of Ansible, but I am the developer of a tool called JC that JSONifies the output of many commands and file-types and I got some feedback that it might be good to integrate JC into Ansible as a plugin so admins can execute arbitrary commands on the remote devices and receive structured data back.

I’m reading the dev docs and it looks like something like this would be a Filter Plugin. Is that correct?

JC is written in Python (only supports Python 3.6+). JC supports 55 command and file-type parsers that run on Linux, macOS, and FreeBSD.

Is this something that would have any real-world use-cases? I heard a use-case would be for gathering data on devices that don’t have Python installed on them since the filter would be run on the controller. Would it be relatively simple to wrap JC into the appropriate plugin type?

[https://github.com/kellyjonbrazil/jc](https://github.com/kellyjonbrazil/jc)

I’m happy to start working on this, but want to make sure I’m barking up the right tree.

Thanks,  
Kelly

---

<div class="post-metadata">

**Author:** ![Kelly\_Brazil](https://avatars.discourse-cdn.com/v4/letter/k/898d66/32.png) [@Kelly\_Brazil](https://forum.ansible.com/u/Kelly_Brazil)\
**Post date:** [July 30, 2020, 12:20am UTC](https://forum.ansible.com/t/filter-plugin-to-convert-executed-command-output-to-json/33522/2 "2020-07-30T00:20:34Z")

</div>

I should add that, when used as a library, JC actually returns a Dict or List of Dicts, not JSON, but can easily convert to JSON before sending to the end-user, if needed.

---

<div class="post-metadata">

**Author:** ![maxamillion](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/maxamillion/32/98_2.png) [@maxamillion](https://forum.ansible.com/u/maxamillion)\
**Post date:** [July 30, 2020, 4:49pm UTC](https://forum.ansible.com/t/filter-plugin-to-convert-executed-command-output-to-json/33522/3 "2020-07-30T16:49:39Z")

</div>

> Hi everyone!
> 
> I'm not a day-to-day user of Ansible, but I am the developer of a tool called JC that JSONifies the output of many commands and file-types and I got some feedback that it might be good to integrate JC into Ansible as a plugin so admins can execute arbitrary commands on the remote devices and receive structured data back.
> 
> I'm reading the dev docs and it looks like something like this would be a Filter Plugin. Is that correct?
> 
> JC is written in Python (only supports Python 3.6+). JC supports 55 command and file-type parsers that run on Linux, macOS, and FreeBSD.
> 
> Is this something that would have any real-world use-cases? I heard a use-case would be for gathering data on devices that don't have Python installed on them since the filter would be run on the controller. Would it be relatively simple to wrap JC into the appropriate plugin type?
> 
> [https://github.com/kellyjonbrazil/jc](https://github.com/kellyjonbrazil/jc)
> 
> I'm happy to start working on this, but want to make sure I'm barking up the right tree.

Hello Kelly!

Thank you for reaching out, the timing is perfect because I was just  
discussing the possibility of using jc as the backend for something  
the other day in a discussion about parsing unstructured output into  
structured data (big fan of your work by the way).

I'd love to have JC as a filter plugin in the ansible.posix  
Collection[0]! Thank you for suggesting it.

I'd also like to explore the idea of a module\_util that provided the  
main integration interface for modules[1] to utilize JC for backend  
processing of data coming from arbitrary commands run by the  
module\_util basic cli helper functions[2] such as run\_command.  
However, for the use case of the module\_util we'd have to consider  
vendoring JC into that Ansible Collection so that it may be properly  
bundled and sent to the remote nodes as part of the AnsiballZ  
payload[3] without requiring JC to be installed on every remote node  
under Ansible's management.

Let me know your thoughts, I look forward to continuing this discussion.

Thank you,  
-AdamM

[0] - [https://docs.ansible.com/ansible/latest/user\_guide/playbooks\_filters.html](https://docs.ansible.com/ansible/latest/user_guide/playbooks_filters.html)  
[1] - [https://docs.ansible.com/ansible/latest/dev\_guide/developing\_modules\_general.html](https://docs.ansible.com/ansible/latest/dev_guide/developing_modules_general.html)  
[2] - [https://github.com/ansible/ansible/blob/devel/lib/ansible/module\_utils/basic.py](https://github.com/ansible/ansible/blob/devel/lib/ansible/module_utils/basic.py)  
[3] - [https://docs.ansible.com/ansible/2.9/dev\_guide/developing\_program\_flow\_modules.html#ansiballz](https://docs.ansible.com/ansible/2.9/dev_guide/developing_program_flow_modules.html#ansiballz)

---

<div class="post-metadata">

**Author:** ![Kelly\_Brazil](https://avatars.discourse-cdn.com/v4/letter/k/898d66/32.png) [@Kelly\_Brazil](https://forum.ansible.com/u/Kelly_Brazil)\
**Post date:** [July 30, 2020, 5:13pm UTC](https://forum.ansible.com/t/filter-plugin-to-convert-executed-command-output-to-json/33522/4 "2020-07-30T17:13:39Z")

</div>

Hi Adam,

Excellent - I’m fully supportive and am happy to assist in any way. Looking forward to working on this project!

Kelly

---

<div class="post-metadata">

**Author:** ![maxamillion](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/maxamillion/32/98_2.png) [@maxamillion](https://forum.ansible.com/u/maxamillion)\
**Post date:** [July 31, 2020, 8:12pm UTC](https://forum.ansible.com/t/filter-plugin-to-convert-executed-command-output-to-json/33522/5 "2020-07-31T20:12:03Z")

</div>

> Hi Adam,
> 
> Excellent - I'm fully supportive and am happy to assist in any way. Looking forward to working on this project!

Kelly,  
&nbsp;&nbsp;&nbsp;&nbsp;Sounds good, I don't know when/if I'd have the cycles to commit to  
doing any work towards this effort but I'm on board with it. Something  
else that was brought up to me recently is that the insights-core[0]  
project has over 200 parsers for various linux things and might be of  
interest to either JC, Ansible, or both so I'm planning to try and  
find some time to look at these and see where/how we can utilize them.

I've also been considering the best place for the JC integration and I  
think community.general is a solid place for it. If you have the time  
and/or inclination, I'd be happy to review a pull request against the  
community.general[1] Collection.

Thank you again,  
-AdamM

[0] - [https://github.com/RedHatInsights/insights-core](https://github.com/RedHatInsights/insights-core)  
[1] - [https://github.com/ansible-collections/community.general](https://github.com/ansible-collections/community.general)

---

<div class="post-metadata">

**Author:** ![Kelly\_Brazil](https://avatars.discourse-cdn.com/v4/letter/k/898d66/32.png) [@Kelly\_Brazil](https://forum.ansible.com/u/Kelly_Brazil)\
**Post date:** [July 31, 2020, 9:11pm UTC](https://forum.ansible.com/t/filter-plugin-to-convert-executed-command-output-to-json/33522/6 "2020-07-31T21:11:59Z")

</div>

Hi Adam,

Very interesting - thank you for sending those resources. I’ll check them out. I’ll see if I can get a first stab at a community.general collection going.

Cheers,  
Kelly

---

<div class="post-metadata">

**Author:** ![Kelly\_Brazil](https://avatars.discourse-cdn.com/v4/letter/k/898d66/32.png) [@Kelly\_Brazil](https://forum.ansible.com/u/Kelly_Brazil)\
**Post date:** [August 7, 2020, 5:40pm UTC](https://forum.ansible.com/t/filter-plugin-to-convert-executed-command-output-to-json/33522/7 "2020-08-07T17:40:37Z")

</div>

Hi Adam,

I created a basic PR: [https://github.com/ansible-collections/community.general/pull/750](https://github.com/ansible-collections/community.general/pull/750)

More than happy to extend this as needed.

Thanks,  
Kelly
