kwjr_get()
#
Retrieve the first record from a JSON list or dictionary that matches the given id
. If the record is not found and KW_CREATE
is set, a new record is created using json_desc
. The function supports extracting the record from the list or dictionary if KW_EXTRACT
is set.
Prototype
json_t *kwjr_get(
hgobj gobj,
json_t *kw, // NOT owned
const char *id,
json_t *new_record, // owned
const json_desc_t *json_desc,
size_t *idx, // If not null, set the index in case of an array
kw_flag_t flag
);
Parameters
Key |
Type |
Description |
---|---|---|
|
|
Pointer to the GObj context. |
|
|
JSON object or array containing the records. Not owned by the caller. |
|
|
The identifier of the record to retrieve. |
|
|
A new record to insert if |
|
|
JSON descriptor defining the structure of the records. |
|
|
Pointer to store the index of the found record in case of an array. Can be NULL. |
|
|
Flags controlling the behavior of the function, such as |
Return Value
Returns a pointer to the found or newly created JSON record. If KW_EXTRACT
is set, the record is removed from kw
. Returns NULL if the record is not found and KW_CREATE
is not set.
Notes
If kw
is a dictionary, the function searches for a key matching id
. If kw
is a list, it searches for a record where the id
field matches. If KW_CREATE
is set, a new record is created using json_desc
and new_record
. If KW_EXTRACT
is set, the record is removed from kw
and returned with an increased reference count.
Prototype
// Not applicable in JS
Prototype
# Not applicable in Python
Examples
// TODO C examples
// TODO JS examples
# TODO Python examples