4 ms·
I like jq (https://stedolan.github.io/jq/ https://stedolan.github.io/jq/) for this purpose. It's a very flexible tool for filtering, querying and manipulating
by teraflop 6y ago
I like jq (https://stedolan.github.io/jq/ https://stedolan.github.io/jq/) for this purpose.
It's a very flexible tool for filtering, querying and manipulating JSON data, but when run with no arguments, it performs a no-op transformation that just pretty-prints its input.
- kabacha 6y agojq is yet another bloated syntax to learn and I'd definitely refrain from suggesting it to anyone whos not working with json everyday.
- gen220 6y agoI tend to agree, regretfully. I’ve unfortunately often seen coworkers spend half an hour painstakingly crafting and debugging a jq query, that could have been cobbled together in a few minutes with grep and sed. I think the issue is that jq’s interface makes it really hard to “narrow in” on the right solution, whereas grep is much more forgiving.
- michaelcampbell 6y agoI agree in the general case, but the syntax for pretty printing which is what he is doing is literally nothing. Or 'jq', if you include the binary name. Hardly "bloated".
- xgt001 6y agoAgreed about the bloated syntax bit. Whenever I need to work with jq , I tend to trial with jid first and then use the actual syntax with jq. Convoluted if you think about it....
- sigmonsays 6y agoi dont know if i'd call its syntax bloated at all. jq is something i've hated learning but powerful beyond tying grep and awk together. jq is a tool, and like every tool, requires some upfront learning. Once mastered its much more productive than the grep/awk/friends solution. Take this example JSON <pre> { "code": 42, "items": [ { "type":"color", "name":"red", "rgb": [120, 2, 2 ]}, { "type":"color", "name":"green", "rgb": [2, 120, 2]} ] } </pre> for instance, to grab the rgb field for the color green... jq -r '.items | .[] | select(.name=="green") | .rgb
- benibela 6y agoAn alternative would be to use XPath 3.1. I am implementing XPath in a tool called Xidel. There the syntax for the example is much simpler: xidel - -e '?items ?* [?name="green"] ?rgb' Depends what kabacha means with bloated. The XPath syntax is more verbose, but less cryptic
- dvirsky 6y agojq doesn't come pre-installed with every OS, python's json.tool does. So it's always there when you need it, no installation required, which is why I put it the same category of all those classic command-line tools.
- philwelch 6y agoI don’t actually believe my last Linux install came with a system Python. And as a Python developer I always end up using some tool or another to manage installations of multiple Python versions anyway. Furthermore jq just works as a classic command-line tool.
- traviscj 6y ago> ... just works as a classic command-line tool. impossible to understate the value in: not frequently fucking up your ability to run the critical/mundane/everyday/musclememory commands you've come to rely on after maybe 100+ invocations/week as far back as you can remember just because someone you've never met wanted to bump the .ruby-version in your java monorepo
- dvirsky 6y agoWhat Linux distro do you use that it doesn't have Python on it?