
Ask HN: JSON Output for CLI Tools? - zeisss
I am currently our public command-line tool some love and although we officially have an `--output=json` flag, it rarely works or does anything useful.<p>* While thinking about how to fix&#x2F;implement this for more commands I was wondering if this kind of more structured output is actually of interest&#x2F;use for developers&#x2F;devops&#x2F;SRE?<p>Some context: The tool in question is a client for our API and used for validation + updating resources and triggering long running loadtest jobs. Users are developers, although we also recommend it for integration into CI&#x2F;CD pipelines etc.<p>Any feedback is welcome :)
======
mikece
If the idea is to have output from CLI apps/scripts that can be easily parsed
so that chaining scripts together without regexing yourself to death is the
goal this sounds like what PowerShell Core (which runs on macOS and Linux as
well) does: PS commands return objects -- with a default .ToString() output if
you don't grab the result and use it in the next step/script -- allowing easy
object.property accessors as well as foreach iteration if the command returns
a list/array of objects.

~~~
zeisss
I understand the idea for fetching / listing resources, e.g. list me all ec2
machines.

My confusion is more about general logs ("preparing output in /tmp/randomid")
and progress updates ("the job is 25% done", "deploying cluster", "docker
image download: 90%"). Is that actually of interest as structured output or
should that remain as human readable on stderr?

------
maerF0x0
I find json output massively valuable because I combine it with `jq` instead
of having to try and cut (or other command) slice up responses.

------
viraptor
If your json-vs-text output drifts often, you could make the backing objects
the same. AWS kind of does it in their cli tool. It's all objects and json
inside, but you see nicely rendered tables. "\--output=json" gives you the
real/raw data.

