Re:Jq Internals: Backtracking (2017)
by capableweb on Thursday October 06, 2022 @05:25AM
(#33106255)
If you're used to S-expressions/know a bit of Clojure, `jet` is a similar tool that not only allows you to convert between JSON <> EDN, but also has a tiny query language built-in, that is just normal Clojure functions.
Clojure really excels at data querying/manipulation, so `jet` is very ergonomic to use.
One example:
$ echo '{"anApple": 1}' | jet -i json -k '#(-> % csk/->kebab-case keyword)' -o edn
{:an-apple 1}
Since starting to use jet, I haven't found anything jq could do that jet couldn't also do but with the additional feature of actually being able to read what I've done with it days later.I have a hard time suggesting such a thing, because I find JMESPath incredibly inferior to jq's expressiveness, but if you're in the AWS ecosystem much, you may enjoy https://github.com/jmespath/jp#readme which uses the same query language as does awscli (https://docs.aws.amazon.com/cli/latest/userguide/cli-usage-f...). That may at least pay more dividends than keeping jq's language in your head where it will only ever be used by jq
jqp the Text User Interface for playing about with jq might help a bit.
You can have your input JSON terminal left, the output post jq terminal right and interactively edit your jq script elements above.
( based upon the Go implementation of jq )
Re:Jq Internals: Backtracking (2017)
by bachmeier on Wednesday October 05, 2022 @09:29PM
(#33103275)
dsq works for me: https://github.com/multiprocessio/dsq
> dsq registers go-sqlite3-stdlib so you get access to numerous statistics, url, math, string, and regexp functions that aren't part of the SQLite base. (https://github.com/multiprocessio/dsq#standard-library)
Ah, I wondered if they rolled their own SQL parser, but no, I now see the sqlite.go in the repo and all is made clear
There’s some limitations in dsq which means it doesn’t query sub objects that have varying fields - they just remain as JSON strings
Re:Jq Internals: Backtracking (2017)
by pcthrowaway on Wednesday October 05, 2022 @11:16PM
(#33103958)
The trick is to use it daily. The learning curve isn't worse than vim
To use it daily you need a reason, or have the time & will to practice it.
Re:Jq Internals: Backtracking (2017)
by pcthrowaway on Thursday October 06, 2022 @03:56AM
(#33105672)
Fair. I guess I think anyone using jq occasionally could probably be using it daily as well. Dealing with JSON data is pretty much standard for anyone developing or consuming a rest API
> I guess I think anyone using jq occasionally could probably be using it daily as well.
No. Occasionally: "at infrequent or irregular intervals; now and then."
Re:Jq Internals: Backtracking (2017)
by adammarples on Friday October 07, 2022 @10:46AM
(#33122092)
Columnq is pretty amazing, fully SQL, you can even join them to CSV etc
I wish there was something for querying json that had more of a xpath or even a sql-like syntax, or GraphQL with the addition of wildcards.