% duckdb -json -c " select license->>'key' as license, count(*) as count from 'repos.json' group by 1 order by count desc" [{"license":"bsd-3-clause","count":23},{"license":"apache-2.0","count":5},{"license":null,"count":2}]
我们甚至可以在DuckDB完成重活之后,使用jq来美化输出:
% duckdb -json -c " select license->>'key' as license, count(*) as count from 'repos.json' group by 1 order by count desc" | jq [ { "license": "bsd-3-clause", "count": 23 }, { "license": "apache-2.0", "count": 5 }, { "license": null, "count": 2 } ]
% duckdb -c " select license->>'key' as license, count(*) as count from read_json('https://api.github.com/orgs/golang/repos') group by 1 order by count desc"
引用链接
[1] jq: https://jqlang.github.io/jq/ [2] DuckDB as the New jq: https://www.pgrs.net/2024/03/21/duckdb-as-the-new-jq/ [3] DuckDB: https://duckdb.org/ [4] SQLite: https://www.sqlite.org/ [5] jq: https://jqlang.github.io/jq/ [6] PostgreSQL JSON Functions: https://www.postgresql.org/docs/current/functions-json.html [7] 一次一个向量地撕裂深层嵌套的JSON: https://duckdb.org/2023/03/03/json.html