Live data from Hacker News

Extracting Objects Recursively with Jq

til.simonwillison.net

61–70 of 76 posts

Re: Extracting Objects Recursively with Jq

#61
post #38

JSON data is also a valid Prolog term, and the declarative programming language Prolog is ideally suited for handling tree-shaped data. Using for example Scryer Prolog, we can conveniently relate the data to a flat list of items with Prolog's built-in grammar mechanism, definite clause grammars (DCGs): flat_json(JSON) --> { JSON = {A,B,C,D,E,F,_:Cs} }, [{A,B,C,D,E,F}], flat_items(Cs). flat_items([]) --> []. flat_item…

Awesome technique, I need to get back into Prolog stuff :) love your videos btw.

Re: Extracting Objects Recursively with Jq

#62

I tend to use jq a lot. As others have said, sometimes jq can be hard to grasp. Often it requires multiple attempts to get the correct answer. To make it a little easier for me, I've written a helper function[0] that combines it with fzf[1] to run jq as a REPL on any json. It allows to incrementally alter your DSL without having to continually call jq. This is similar to jid/jiq but a little more powerful. It include…

Just sharing my take on that interactive jq (or anything else) repl:

https://github.com/kbd/setup/blob/master/HOME/bin/fzr

It's just an fzf wrapper that sets up temporary files and so on. It works really well; it's amazing all the things one can use fzf for.

Re: Extracting Objects Recursively with Jq

#65

Forget about jq. JSONata is much more powerful - http://docs.jsonata.org/overview.html

Yea what's going on here, you have a couple of other comments pushing Jsonata? You an author or something?

Not at all. After using jq in the past and seeing both it's potential and flaws I was looking for something more powerful and easy to use, so I stumbled upon JSONata and became a fan.

Re: Extracting Objects Recursively with Jq

#66

I tend to use jq a lot. As others have said, sometimes jq can be hard to grasp. Often it requires multiple attempts to get the correct answer. To make it a little easier for me, I've written a helper function[0] that combines it with fzf[1] to run jq as a REPL on any json. It allows to incrementally alter your DSL without having to continually call jq. This is similar to jid/jiq but a little more powerful. It include…

Another option for interactive version is: https://sr.ht/~gpanders/ijq/

Re: Extracting Objects Recursively with Jq

#67

There's a real need for a tool like jq, but jq unfortunately isn't it. What I mean is this: the functionality offered by jq (parsing json on the command line and extracting what you need from it) is really needed in many modern data processing tasks, but jq's DSL is one of the most horrible thing I've had to learn in recent years. The only way a casual user of that thing can hope to succeed in actually crafting a wor…

You might prefer gron for this use case: https://github.com/tomnomnom/gron

Re: Extracting Objects Recursively with Jq

#68

I tend to use jq a lot. As others have said, sometimes jq can be hard to grasp. Often it requires multiple attempts to get the correct answer. To make it a little easier for me, I've written a helper function[0] that combines it with fzf[1] to run jq as a REPL on any json. It allows to incrementally alter your DSL without having to continually call jq. This is similar to jid/jiq but a little more powerful. It include…

Why not just use inotify (or similar tools offered by other OS)?

Re: Extracting Objects Recursively with Jq

#69
post #33

To better appreciate the structure of the document the author is dealing with (and to cast a bit of light on which words are variables in the document and which are `jq` syntax. I offer a shameless plug to a one liner well, I would but the result is "too long for a HN comment" so here a bunch is sniped out of the middle (unedited the result would currently be 140 lines) curl -s https://hn.algolia.com/api/v1/items/279…

Looks a bit like `jq -rc '[path(..)|map(strings//"[]")]|unique[]|"."+join("|.")'`, but might I suggest `jq -rc '[paths|map(("."+strings)//"[]")|join("")]|unique[]'`?

There is no need to guess, you can just look in the repo.

I like the explicit separators when I'm reading them instead of writing them. Helps the individual steps stand out for me.

Is there a reason other than a more compact line?

Re: Extracting Objects Recursively with Jq

#70
post #10

I've really loved having jq at my disposal ever since learning about it, but I feel like it took the combination of it and gron [1] to really transform my debugging and JSON workflows. 1: https://github.com/TomNomNom/gron

`gron` is really lifesaver for people like me who can't survive JSON (by simply looking / reading it) but have to deal with JSON on a daily basis (REST API, K8s related). Often times a few gron / ungron runs save the day ;-)
Post reply on HN