Have you seen gron[0]? It's similar: flattens JSON documents to make them easily greppable. But it also can revert (ie, ungron) so you can pipe json to gron, grep -v to remove some data, then ungron to get it back to json.
Maybe GP meant that jq can do selection as well, i.e. that grepping is redundant after jq. But jq is much more complicated to learn and grep works on all inputs (not just json), so it makes a lot more sense to learn and use grep properly.
jq seems very powerful. I don't deal with json all that often and my most common use case (by far) is `jq '.' -C` and it took a few tries for me to remember that syntax.
The idea of flattening, grepping, then reverting sounds very appealing and sounds like a better fit for me.
I find it useful when I don't know what the json schema is.
Then you can just do a quick gron + grep and find where the interesting parts of a large json document are.
There are cases when you have some complicated json and just want to search for stuff. Then you use grep + gron. There are cases when you want a complete json processing tool. Then you use jq. You can probably simulate each approach with the other approach, but the code needed to this is just too tedious to write. So you use whatever tool fits your use case.
That's actually a nice lifehack. Much simplier than jq. Unfortunately, would be harder to make all kinds of logical conditions for which jq allows (even if not that intuitively).
It still feels like there must be something in between, some way to make queries with json more naturally, than with jq, yet with enough power.
jq is certainly a unique language, which makes it unfamiliar to work with. Intuitiveness and natural feeling comes when one has gotten familiar with it after a bit of practice and reading the manual, though. It's a very well thought-out language. A very nice design.
It might help to recognize how it's influenced by shell languages and XPath, if you're familiar with those.
Well, no arguing there, it is indeed. And I use it from time to time. However, it's not like I need a tool like that every day, and if I'm no using it for a week I usually need to "learn" it all over again.
Comments (120) 40 threads
Show all comments
Showing thread 2 of 40
[0] https://github.com/tomnomnom/gron
The project linked to is from 2014 with last update in 2015.and it is on NPM...
What is left to say? Thank you!
[1]:https://github.com/stedolan/jq
The idea of flattening, grepping, then reverting sounds very appealing and sounds like a better fit for me.
I don't think you really need neither `.` nor `-C`. Just `jq` seems to do the same colored output of the input by default.
Continue this thread — 3 replies
There are cases when you have some complicated json and just want to search for stuff. Then you use grep + gron.
There are cases when you want a complete json processing tool. Then you use jq.
You can probably simulate each approach with the other approach, but the code needed to this is just too tedious to write. So you use whatever tool fits your use case.
It still feels like there must be something in between, some way to make queries with json more naturally, than with jq, yet with enough power.
It might help to recognize how it's influenced by shell languages and XPath, if you're familiar with those.