by pgl on 11/3/22, 7:55 AM with 132 comments
by asicsp on 11/3/22, 9:08 AM
* "Bringing the Unix philosophy to the 21st century (2019)" (https://blog.kellybrazil.com/2019/11/26/bringing-the-unix-ph...) - https://news.ycombinator.com/item?id=28266193 238 points | Aug 22, 2021 | 146 comments
* "Tips on adding JSON output to your CLI app" (https://blog.kellybrazil.com/2021/12/03/tips-on-adding-json-...) - https://news.ycombinator.com/item?id=29435786 183 points | 11 months ago | 110 comments
by ducktective on 11/3/22, 8:48 AM
Or pipe it into rq [2] to convert the format to yaml, toml etc.
[1]: https://stedolan.github.io/jq/tutorial/ [2]: https://github.com/dflemstr/rq#format-support-status
by spinningslate on 11/3/22, 9:03 AM
When wrestling with sed/awk in trying to parse results of a shell command, I've often thought that a shell-standard, structured outpout would be very handy. Powershell[0] has this, but it's a binary format - so not human-readable. I want something in the middle: human- and machine-readable. Without either having to do parsing gymnastics.
jc isn't quite that shell standard, but looks like it goes a long way towards it. And, of course, when JSON falls out of fashion and is replaced by <whatever>, `*c` can emerge to fill the gap. Nice.
by vesinisa on 11/3/22, 9:15 AM
Why does this site recommend using "paru", "aura" or "yay" to install it on Arch? I have been using Arch for a decade or so but have never even heard of such tools. They don't even have pages in the Arch wiki, and only yay ("Pacman wrapper and AUR helper written in go") is available via the standard repository.
Begs the question: what is so wrong with plain pacman?
EDIT: Okay so seems they were previously on AUR and once accepted to community repository they just forgot to stop recommending an AUR wrapper for installing: https://github.com/kellyjonbrazil/jc/commit/f2dd7b8815edc92e...
EDIT2: Created a PR with the GitHub.dev editor .. Absolutely blown away by how easy it was! Feels like the future of development.. https://github.com/kellyjonbrazil/jc/pull/310
by dmoura on 11/3/22, 11:07 AM
I am the author of SPyQL [1]. Combining JC with SPyQL you can easily query the json output and run python commands on top of it from the command-line :-) You can do aggregations and so forth in a much simpler and intuitive way than with jq.
I just wrote a blogpost [2] that illustrates it. It is more focused on CSV, but the commands would be the same if you were working with JSON.
[1] https://github.com/dcmoura/spyql [2] https://danielcmoura.com/blog/2022/spyql-cell-towers/
by garfieldnate on 11/6/22, 9:45 AM
That said, I would argue that JSONLines is a better universal output format when you're dealing with pipelines. If the output is one giant JSON array, then you have to wait for a long-running program to finish completely before the output can be passed on to the next long-running program. If you output one JSON line at a time as you process your input, then the next program in the pipeline can get started on processing already without waiting for the first to finish completely.
by enriquto on 11/3/22, 8:41 AM
by pgl on 11/3/22, 8:00 AM
Blog post with examples here: https://blog.kellybrazil.com/2020/08/30/parsing-command-outp...
by anecdotal1 on 11/3/22, 12:01 PM
by rob74 on 11/3/22, 9:14 AM
by HyperSane on 11/3/22, 6:05 PM
by otikik on 11/3/22, 11:47 AM
by nixcraft on 11/3/22, 9:00 AM
dig +yaml google.com
by khiqxj on 11/3/22, 3:32 PM
- It has to parse output of commands which may or may not be intended to be parsed and may or may not have a predictable format. The only way to overcome this is if this program becomes one of the Big Four "UN*X command output -> data" converters
- It casts things to "float/int"
- Depending on who made this library, the output itself may not be strict / predictable. Perhaps it will output JSON with two different key names in two different scenarios.
And don't forget that any of these issues will still come up even if they are accommodated for, due to versions of programs changing without the author of this tool knowing.But yeah basic things having intrinsic shortcomings is a given, when you're using UN*X.
From the nested article:
> Had JSON been around when I was born in the 1970’s Ken Thompson and Dennis Ritchie may very well have embraced it as a recommended output format to help programs “do one thing well” in a pipeline.
They had S-expressions and plenty more options. They also could have just made a format as you can tell with thousands of ad-hoc trendy new formats like YAML and TOML being spewed out every recent year now that programmers discovered data structures.
by fabianthomas on 11/5/22, 10:24 AM
Even when using jq (written in C) my quick tests show that parsing json is really slow compared to parsing with simple unix tools like awk. I suspect that to come from the fact that the parser has to check the full json output first in order to print a result, while awk does not care about syntax of the output.
I compared two shell scripts both printing the ifindex of some network device (that is the integer in the first column) 10 times.
Using awk and head combined gives me 0,068s total time measured with the time command.
Using ip with the -j flag together with jq gives 0,411s.
Therefore the awk approach is 6 times faster. And here I used a binary (ip) that already supports json output and doesn't even need the mentioned jc.
While this whole test setup is somewhat arbitrary I experienced similar results in the past when writing shell scripts for, e.g., my panel. Reach out to me if you are interested in my test setup.
by uvesten on 11/3/22, 8:49 AM
by mg on 11/3/22, 9:59 AM
dig example.com | jc --dig
Seems a bit redundant. Maybe it should be the other way round? jc dig example.com
Similar to how you do time dig example.com
by pastage on 11/3/22, 10:21 AM
The power of plain text pipes is that you do not interpret them and that makes them fast, that is usefull because you handle both 100 bytes, 1MB and 1TB as input. You choose what you parse keeping it simple, fast and usually error free. This tool miss the, fast, simple and human readable part of debugging pipes. Which is fine!
by naikrovek on 11/3/22, 9:31 PM
minor updates to command-line tools can and do subtly alter the textual output of the tool, and the outputs of these tools are not standardized.
This is a step towards "objects passing messages" as originally conceived by Alan Kay, if my incomplete understanding of what he's said is correct, and that's a good thing, I think. Objects passing messages around is a very solid model for computing, to me. Note that I am stupid and don't understand much, if I'm honest.
by synergy20 on 11/3/22, 12:12 PM
I'd like to use it on embedded systems, where python is too large to fit. this tool can be widely deployed just like awk|sed|etc but it has to be in C for that.
by codedokode on 11/3/22, 12:31 PM
It is obvious that CLI commands should produce machine-readable output because they are often used in scripts, and accept machine-readable input as well. Using arbitrary text output was a mistake because it is difficult to parse, especially when spaces and non-ASCII characters are present.
A good choice would be a format that is easily parsed by programs but still readable by the user. JSON is a bad choice here because it is hard to read.
In my opinion, something formatted with pipes, quotes and spaces would be better:
eth0:
ip: 127.15.34.23
flags: BROADCAST|UNICAST
mtu: 1500
name: """"Gigabit" by Network Interfaces Inc."""
Note that the format I have proposed here is machine-readable, somewhat human-readable and somewhat parseable by line-oriented tools like grep. Therefore there might be no need for switches to choose output format. It is also relatively easy to produce without any libraries.Regarding idea to output data in /proc or /sys in JSON format, I think this is wrong as well. This would mean that reading data about multiple processes would require lot of formatting and parsing JSON. Instead or parsing /proc and /sys directly, applications should use libraries distributed with kernel, and reading the data directly should be discouraged. Because currently /proc and /sys are just a kind of undocumented API.
Also, I wanted to note that I dislike jq utility. Instead of using JSONPath it uses some proprietary query format that I constantly fail to remember.
by Too on 11/5/22, 10:46 AM
At the same time it’s an epitome of everything that is wrong with current software landscape. Instead of fixing the deficiencies in upstream, once and for all, we just keep piling more and more layers on top.
Programs having structural data and APIs inside, that get translated into human representation - only to be re-parsed again into structural form. What could possibly go wrong?
If you are already in any programming environment, many of the tools already have better built in APIs. I mean who needs an “ls” or timestamp parser. Just use os.listdir or equivalent. As someone previously pointed out in this thread, the ls parser is in fact already broken, unsurprisingly. Mixing tools made for interactive use in automation is never a good idea.
The Unix philosophy sounds romantic in theory, but need structural data, throughout, to work reliably in practice. Kids, go with the underlying apis unless your tool has structured output.
by pessimizer on 11/3/22, 5:06 PM
If this were written in a performant language, if it simply aliased (i.e. invisibly) all common cli commands to a wrapper which would obviate the need for all of the text processing between steps in command pipelines, if it were versioned and I could include the version number in scripts, and finally if I could run versioned scripts through it to compile them into standard bash scripts (a big ask), I'd give it a 3 month test starting today. There'd be nothing to lose.
Just putting that out there for people who like to rewrite things in Rust. A slightly different version of this concept could allow for nearly friction-free adoption.
by esskay on 11/3/22, 9:00 AM
by wooptoo on 11/3/22, 11:56 AM
by hinkley on 11/3/22, 5:14 PM
The itch I can’t seem to scratch is how to run tasks in parallel and have logs that are legible to coworkers. We do JSON formatted logs in production and I’m wondering if something like this would help solve that set of problems.
by wodenokoto on 11/4/22, 12:26 PM
Nushell that hit the front page earlier this week seemed to me to be limited by "compatible" apps, but wrapping all the big ones in a json converter superficially seems like a great solution to me.
by menjaprunes on 11/3/22, 8:57 AM
I love it
by fimdomeio on 11/3/22, 11:42 AM
by friendzis on 11/3/22, 10:19 AM
by exabrial on 11/3/22, 3:45 PM
by psadri on 11/3/22, 9:31 PM
by sindoc on 11/3/22, 10:20 AM
by visarga on 11/3/22, 8:56 AM
by deafpolygon on 11/3/22, 11:07 AM
by berkes on 11/3/22, 12:00 PM
In my perfect world (which, obviously doesn't exist), commands from tools "in the wild" are at least three letters long. With historical exceptions for gnutools: preferably they'd take the three-letter space, but two-letters (cd, ls, rm etc) is fine.
Two letter space outside of gnutools, is then reserved for my aliases. If jsonquery is too long to type, AND I lack autocomplete, then an alias is easy and fast to make. alias jq=jsonquery.
In the case of this tool, it will conflict with a specialised alias I have: `alias jc=javac -Werror`. Easy to solve by me with another alias, but a practical example of why I dislike tools "squatting" the two letter namespace.