_Vi

joined 2 years ago
[–] _Vi@programming.dev 6 points 1 month ago* (last edited 1 month ago) (1 children)

At first I thought that it is like SQLite, but for JSON, not just "JQ-lite".


Speaking of JSON and queries, it is worth to mention DuckDB's JSON features. This allows you to use actual SQL to query JSON.

Here is example of a DuckDB analogue of $.orders[?(@.status.#equals('delivered'))][*].items from JQLite documentation:

duckdb -c "from (from demo.json select unnest(orders)->>'status' as status, cast(unnest(orders)->'items' as json[]) as items) select unnest(items) as delivered_items where status='delivered'"

┌─────────────────────────────────────────────────┐
│                 delivered_items                 │
│                      json                       │
├─────────────────────────────────────────────────┤
│ {"productId":"p1","quantity":1,"price":1299.99} │
│ {"productId":"p2","quantity":2,"price":1599.99} │
└─────────────────────────────────────────────────┘