--json Outputs JSON objects for --nodes, --request-telemetry/position
In a attempt to make the output of meshtastic a bit more machine parsing friendly (eg by nushell) I propose the addition of '--json' to switch the output to something easily parsable when piped on the commandline.
Am I alone in thinking that any output produced in the presence of a --json option should actually be readable as a JSON document? I'm quite happy for other formats to exist, but please let's not mangle existing standards. Transforming JSON is a straightforward task, for which many support libraries exist. Parsing invented almost-JSON formats isn't.
It appears that these formats are, in fact, JSON (everything is produced via json.dumps) and could be treated as such.
However, they do look fairly ad-hoc and I think we need a consistent approach, as we're discussing over in #569 -- the discussed plan there so far has largely been to do as little modification of protobufs as we can other than turning them to JSON, and to identify things by the (lowercased) name of the protobuf. This will probably require a bit of internal refactoring for some things (e.g. I don't believe right now we're holding onto a copy of the actual NodeInfo protobufs for nodes, but packing into our own structure instead), but would be much more easily extensible to any other commands and straightforwardly documented in terms of the protobuf definitions.
I totally agree.. it would be preferred to eliminate conversions back and forth into JSON like this. Refactoring the whole codebase to facilitate a clear separation of concern / interface was not my intention. I guess It's best to close this PR and keep the effort to myself while a proper solution is drafted in Discussion: machine-readable output