Interesting. I usually pipe JSON to “gron | percol”. The result key is usually (not always) ready to feed to jq as a selector.
Fx is somewhat the same idea.
For anyone wondering what a complex jq script looks like, check this out:
This is… unfortunate. People should reach for a different, more readable tool when jq gets beyond a single line. (I say this as someone who likes jq for what it’s good at.)
jq is a good language for working with streaming data. It’s not perfect, but I’m not sure in which language or with which other tool I would have rather written my own complex jq script. The ability to write modules is nice because it allows for factoring out code.
Thanks for this, it’s a way more readable complex script.
Personally, for something that’s intended to be short lived or that has varied structure, I’d probably reach for Python with JMESPath. For something long-lived and performance critical, I’m not sure. I’ve used Clojure and Haskell with success, but today might reach for Rust (and serde) since it’s closer to the top of the heap. I think all of those choices offer more readable and conventional semantics for long scripts.
Critically, though, the jq script (fugly though it may be) will just work without the ecosystem issues the other answers have. “Make sure you have jq installed and run this script” is a lot less likely for a junior to have problems with than “Make sure you have Rust installed and can compile this”.
For now. Is that true of older tools with similar selling points, though? I think about the differences in versions of grep, awk, and sed, and figure similar dialect issues will accrue as time passes.
jq is a really lovely language, especially with version 1.6. I’ve contributed to a set of jq bindings for Go and have a few $WORK projects that make use of it. One is a pubsub library that has jq support in the client (any consumer can filter or transform messages using a jq expression), and one is a sort of rules engine for selecting video transcoding profiles based on the metadata of the source video stream. Its performance is surprisingly decent, too.
I used jq this weekend for the first time
in earnest. I thought hey, coming from JS, I can skip R-ingTFM, but a lot of things didn’t make immediate, intuitive sense. Once the basics clicked (somewhat), though, I’m glad to add it to my toolbox.