3 ms·
Very cool! I am also a big fan of jq. And I think using DuckDB and SQL probably makes a lot of sense in a lot of cases. But I think the examples are very gea
by sshine 3y ago
Very cool!
I am also a big fan of jq.
And I think using DuckDB and SQL probably makes a lot of sense in a lot of cases.
But I think the examples are very geared towards being better solved in SQL.
The ideal jq examples are combinations of filter (select), map (map) and concat (.[]).
For example, finding the right download link:
$ curl -s https://api.github.com/repos/go-gitea/gitea/releases/latest \
| jq -r '.assets[]
| .browser_download_url
| select(endswith("linux-amd64"))'
https://github.com/go-gitea/gitea/releases/download/v1.15.7/gitea-1.15.7-linux-amd64
Or extracting the KUBE_CONFIG of a DigitalOcean Kubernetes cluster from Terraform state:
$ jq -r '.resources[]
| select(.type == "digitalocean_kubernetes_cluster")
| .instances[].attributes.kube_config[].raw_config' \
terraform.tfstate
apiVersion: v1
kind: Config
clusters:
- cluster:
certificate-authority-data: ...
server: https://...k8s.ondigitalocean.com
...
- pgr0ss 3y agoI think that's a fair point. Unnesting arrays in SQL can be annoying. Here is your first example with duckdb: duckdb -c \ "select * from ( \ select unnest(assets)->>'browser_download_url' as url \ from read_json('https://api.github.com/repos/go-gitea/gitea/releases/latest') \ ) \ where url like '%linux-amd64'"
- _flux 3y agoIn case someone else was wondering, one can get a shell-consumable output from that with duckdb -noheader -list