• 0 Posts
  • 1 Comment
Joined 2 years ago
cake
Cake day: August 16th, 2023

help-circle
  • 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} │
    └─────────────────────────────────────────────────┘