jsonknife
jsonknife · Useful jsonb inspection and transformation functions
Overview
PostgreSQL · 11
Usage
Sources:
jsonknife 1.0 provides C functions for extracting and reducing values along declarative paths through jsonb. A path element that is a string selects an object key, a number selects an array index, and an object filters array elements by a matching pattern. Use it for compact, read-only traversal; it does not provide an index access method or JSON mutation API.
Core Workflow
The second argument is a JSON array of paths. Each individual path is itself a JSON array:
The result is a PostgreSQL array containing the matched names. Multiple path arrays may be supplied in the outer array, and traversal can flatten matches found in JSON arrays.
Function Index
knife_extract(jsonb, jsonb) RETURNS jsonb[]preserves JSON values.knife_extract_text,knife_extract_numeric, andknife_extract_timestamptzreturn typed PostgreSQL arrays.knife_extract_min_numeric,knife_extract_max_numeric,knife_extract_min_timestamptz, andknife_extract_max_timestamptzreduce matched values to one bound.knife_date_bound(text, text) RETURNS timestamptzinterprets a partial date using eitherminormaxas the missing-field boundary.
All functions are declared STRICT and IMMUTABLE; a NULL input produces NULL, and type conversion errors abort the statement. The implementation directly uses PostgreSQL’s internal jsonb C structures and dates from early jsonb releases. Confirm binary/source compatibility with the target PostgreSQL major version before deployment, and benchmark large documents because extraction walks the supplied JSON rather than using a database index.