Selecto.Advanced.JsonOperations (Selecto v0.3.8)
JSON operations support for PostgreSQL JSON and JSONB functionality.
Provides comprehensive support for JSON path queries, aggregation, manipulation, and testing functions. Works with both JSON and JSONB column types with automatic type detection and optimization.
examples
Examples
# JSON path extraction
selecto
|> Selecto.select([
{:json_extract, "metadata", "$.category", as: "category"},
{:json_extract, "metadata", "$.specs.weight", as: "weight"}
])
# JSON aggregation
selecto
|> Selecto.select([
{:json_agg, "product_name", as: "products"},
{:json_object_agg, "product_id", "price", as: "price_map"}
])
|> Selecto.group_by(["category"])
# JSON filtering
selecto
|> Selecto.filter([
{:json_contains, "metadata", %{"category" => "electronics"}},
{:json_path_exists, "metadata", "$.specs.warranty"}
])
Link to this section Summary
Functions
Create a JSON extraction operation specification.
Determine if an operation is suitable for WHERE clauses.
Determine if an operation is suitable for SELECT clauses.
Validate a JSON operation specification.
Link to this section Functions
Link to this function
create_json_operation(operation, column, opts \\ [])
Create a JSON extraction operation specification.
Link to this function
filter_operation?(operation)
Determine if an operation is suitable for WHERE clauses.
Link to this function
select_operation?(operation)
Determine if an operation is suitable for SELECT clauses.
Link to this function
validate_json_operation(spec)
Validate a JSON operation specification.