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

[FEATURE REQUEST] JC renderer to convert command output to objects #58355

kellyjonbrazil opened this issue Sep 1, 2020 · 1 comment
Feature new functionality including changes to functionality and code refactors, etc.


Copy link

kellyjonbrazil commented Sep 1, 2020

I recently created an Ansible filter plugin for JC ( - I am the author) and it was requested I create something similar for Salt. I believe this would be a renderer serializer (deserializer, to be specific), and an outputter in Salt, though I'm open to other options.

JC is a command-line utility and python library that converts the output of dozens of commands and file-types into a python dict or list of dicts. The JC CLI converts the command output to JSON. Here is a blog post that demonstrates how it can be used in Ansible:

I'm still getting my Salt dev environment set up, but I noticed in the Contributing docs it recommended opening an issue before issuing a PR.

I have created a first draft of the renderer here:

I have created a first draft of the serializer and outputter here:

And here is a first draft of the unit tests:

I would just like to make sure a Renderer is the proper approach and if there are any other pieces missing, like documentation/Changelog before I submit a PR.

The outputter works, but requires a parser parameter passed to it. I didn't know how to get a parameter into the outputter, so I'm using an environment variable:

$ JC_PARSER=uptime salt '*' 'uptime' --out=jc

and here's an example of the serializer in an sls file:

{% set date_out = salt.cmd.run_stdout('date') %}
{% set date_jc = salt.slsutil.deserialize('jc', date_out, parser='date') %}

        - name: >
            echo 'The timezone is {{ date_jc.timezone }}'

The only issue with this setup is that jc needs to be installed on the minions for this to work. I was hoping to have the deserialization happen on the master. If anyone has any suggestions on that I'm open.


@kellyjonbrazil kellyjonbrazil added the Feature new functionality including changes to functionality and code refactors, etc. label Sep 1, 2020
@sagetherage sagetherage added this to the Approved milestone Sep 23, 2020
Copy link

kellyjonbrazil commented Feb 10, 2022

Note, there is a new high-level API for calling jc parsers that can simplify the implementation a bit:

Also, there are now a handful of 'streaming' parsers that return generators that can be iterated over. Not sure if there is a use case for those. In any case, for every streaming parser there is a corresponding 'standard' parser, so streaming parsers can be filtered out if they are not useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Feature new functionality including changes to functionality and code refactors, etc.
None yet

No branches or pull requests

3 participants