12 ms·
I love JQ. But ... I'd never considered its query language to be particularly admirable. If I want to ask questions of some databases, I don't understand why
by rout39574 2y ago
I love JQ. But ... I'd never considered its query language to be particularly admirable. If I want to ask questions of some databases, I don't understand why I'd choose JQ's XPATH-like language to do it.
- hnbad 2y agoPresumably the target audience is people who already frequently use JQ and don't want to juggle different query languages when dealing with different data sources?
- neilotoole 2y agoDeveloper here. That was exactly the target audience. Note that sq doesn't just handle relational DBs, it also has (varying quality) support for CSV, JSON, Excel, and so on. At the time (2013) I wasn't aware of a convenient one-liner mechanism for munging all of those together from the command line.
- AlphaSite 2y agoI think for certain types of data manipulation and querying it’s notable more succinct, sql with CTEs is a little better but still far more verbose than data piping.
- larodi 2y agoA reply by s.o. who sides with your (potentially unpopular) opinion. With all due respect to DSL languages, IMHO only few people can get on this APL-level of abstraction and cryptic choice for APIs..., and would have the nerves to write it. From learning perspective JQ seems much more difficult than RegEX for example, its learning curve is potentially steeper than that of CSS and XPATH, which are other examples for querying tree-like-structs. While LLMs are welcome to write it (the jq) for me, my work has relatively little JSON transformations, and for the most part handling these in python/js/perl is okay as. Stating all this with much fascination for the JQ language itself, as technology, but not as a tool that I find the need for on a daily basis. Besides for me it is much more easier to feed and transform data into Postgres (or even SQLite, which can also be challenging), rather than crunch it w/pandas or R where you can also find fourth generation language capabilities, but performance lags.
- VMG 2y agoWhat I love about `jq` that I can edit my query (or "program") by appending tokens at the end. Similar to unix pipes. With plain SQL that is not easy.
- pkkm 2y agoSounds like PRQL [1]. [1] https://prql-lang.org/ https://prql-lang.org/
- VMG 2y agoKind of. However on first glance it seems like the separator in PRQL is a newline instead of a `|`, which is less ergonomic in a shell.
- pie_flavor 2y agoNewline and pipe mean the same thing and are interchangeable.
- VMG 2y agonice - are there any PRQL CLI tools for json?
- snthpy 2y agoNot directly, but DuckDB, ClickHouse, and GlareDB all support PRQL and they each have CLIs. In a previous HN comment [1] I showed how you can leverage PRQL to make your RDBM's JSON functionality more ergonomic. For example ```sh > prqlc compile <<EOF - | duckdb let get = path obj -> s"""{obj} -> {path}""" let getstr = path obj -> s"""{obj} ->> {path}""" let extract = obj path -> s"""json_extract({obj}, {path})""" from [{data='{"duck": [1, 2, 3]}'}] select { (data | get '$.duck[0]'), (data | getstr '$.duck[1]'), extract data '$.duck[2]'} EOF ┌───────────────────────┬──────────────────────────┬───────────────────────────────────┐ │ "data" -> '$.duck[0]' │ ("data" ->> '$.duck[1]') │ json_extract("data", '$.duck[2]') │ │ json │ varchar │ json │ ├───────────────────────┼──────────────────────────┼───────────────────────────────────┤ │ 1 │ 2 │ 3 │ └───────────────────────┴──────────────────────────┴───────────────────────────────────┘ ``` More details in that post. Unfortunately I don't think this really addresses the grandparent comment though because you're still using jsonpath type expressions to unpack the JSON objects. If you really wanted to use PRQL for everything you would have to first convert and flatten your JSON data into relational tables. 1: https://news.ycombinator.com/item?id=37569946 https://news.ycombinator.com/item?id=37569946
- fer 2y agoSame, if anything I'd look for a SQL-like language for JSON.
- lucideer 2y agoThis! JQ is great because JSON didn't have a query language & needed one. JQ isn't the best query language - it's just the one that won adoption. DBs already have query languages that are mostly superior to JQ's.
- baq 2y agohonestly I'd rather have sql for json than jq for a database... guess this is exactly what clickhouse-local does