I think a better way to handle your approach would be to attempt to make it automatic; for example, if a program could detect its output as "not a TTY" and then (somehow) make an intelligent determination about what kind of object to pass (i.e. if there was a way for the program on the other end of the pipe to say "Send me object data if you want!") then it would be useful, coupled with programs or commandlets to do filtering.
Having to manually specify "you, output JSON! And you, input JSON! and also filter based on this difficult to remember for most people syntax!" would be cumbersome; much easier to have "commandlets" built into the shell to handle this sort of thing in a sort of composable pipeline. For example:
host -t A example.org
| select arecords --limit 1
| ping -c1
| select pings.time --limit 1
| write --append outputfile
As others have said, Powershell supports this, and it's completely awesome to work with. The fact that (assuming proper metadata on the binaries) I can do queries like this is awesome:
~ > Get-Command java -All | Sort-Object Version -Descending
CommandType Name Version Source
----------- ---- ------- ------
Application java.exe 15.0.1.0 C:\Program Files\Java\jdk-15.0.1\bin\java.exe
Application java.exe 11.0.6.0 C:\Program Files\Java\jdk-11.0.6\bin\java.exe
Application java.exe 8.0.2610.… C:\Program Files (x86)\Common Files\Oracle\Java\javapath\java.exe
This lets you, for example, have multiple versions of something installed, and have a script easily and cleanly get a list of all of them and either choose which one to use, or run something on each (e.g. for testing scripts).
There are also a lot of "that's weird but handy" features, like being able to interact with environment variables the same way you do local files:
if (Test-Path 'env:GIT_COMMIT') {
echo "GIT_COMMIT is $Env:GIT_COMMIT"
$commit_hash = $Env:GIT_COMMIT
}
Extremely impressed with Microsoft on this implementation. Also worth noting: you can install Powershell on your Linux or macOS systems and use it there as well. Semi-tempted to try implementing things in Powershell as the only cross-platform shell available.