CiscoDevNet / python-viptela

Cisco Viptela vManage Python CLI/SDK
GNU General Public License v3.0
96 stars 64 forks source link

CLI option --json does not print proper json #117

Closed jacobgarder closed 3 years ago

jacobgarder commented 3 years ago

When using the option --json with the cli-tool to format output as json, the output is done by printing the python dictionary. Eg in show/template.py: pp.pprint(device_template_list)

which gives:

[{ 'configType': 'template',
    'connectionPreference': True,
...

I think it would be better to use proper json-formatting (dubble quotes instead of single, true instead of True etc). For example by using json.dumps(): click.echo(json.dumps(device_template_list, indent=2))

which gives:

[
  {
    "configType": "template",
    "connectionPreference": true,
...

This would enable the output to be parsed or manipulated by other clitools (jq, jawk et al), validated with json-validator and also in communicating directly with vmanager, the format must be proper json-format.

It could be argued that this would be a breaking change if people rely on the formatting to be a python dict, but I still think it would be better to change this now than later. What do you think?

jasonking3 commented 3 years ago

I agree. This makes sense. I'll look at making this change.

jacobgarder commented 3 years ago

I have the code ready if you want to add it. Filed it as a PR now: #131