kw_select()
#
The kw_select
function filters rows from a JSON object or array of dictionaries (kw
) based on the criteria specified in jn_filter
. It returns a new JSON array containing duplicated objects that match the filter. If match_fn
is not provided, the default kw_match_simple
function is used to evaluate matches.
Prototype
PUBLIC json_t *kw_select(
json_t *kw, // not owned
const char **keys,
json_t *jn_filter, // owned
BOOL (*match_fn)(
json_t *kw, // not owned
json_t *jn_filter // owned
)
);
Parameters
Parameter |
Type |
Description |
---|---|---|
|
The input JSON object or array to filter (not owned). |
|
|
|
A list of keys to include in the returned objects. If |
|
JSON object specifying the filter criteria (owned). |
|
|
|
Custom function to evaluate if a row matches the filter criteria. If |
Return Value
Returns a new JSON array (
json_t *
) containing duplicated objects that match the filter criteria.Returns an empty JSON array if no matches are found or if an error occurs.
Notes
Ownership:
The input parameter
kw
is not owned and remains unchanged.The
jn_filter
parameter is owned by the function and will be decremented internally.The returned JSON array is owned by the caller and must be freed when no longer needed.
Error Handling:
Logs an error if
kw
is not a JSON array or object.
Duplication:
Objects in the result array are duplicated with only the specified keys using
kw_duplicate_with_only_keys
.
Prototype
// Not applicable in JS
Prototype
# Not applicable in Python
Examples
// TODO C examples
// TODO JS examples
# TODO Python examples