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…
Extracting Objects Recursively with Jq
61–70 of 76 posts
Re: Extracting Objects Recursively with Jq
#62I 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…
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
#63Earlier quoted context omitted.
Try JSONata instead - http://docs.jsonata.org/overview.html
It doesn't seem to provide a command-line tool, which is the point of jq
Re: Extracting Objects Recursively with Jq
#64Forget about jq. JSONata is much more powerful - http://docs.jsonata.org/overview.html
It doesn't appear to have a CLI, which is the whole point of jq
Re: Extracting Objects Recursively with Jq
#65Forget 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?
Re: Extracting Objects Recursively with Jq
#66I 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…
Re: Extracting Objects Recursively with Jq
#67There'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…
Re: Extracting Objects Recursively with Jq
#68I 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…
Re: Extracting Objects Recursively with Jq
#69To 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[]'`?
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
#70I'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