kw_set_subdict_value()

kw_set_subdict_value()#

The function kw_set_subdict_value() sets a key-value pair inside a subdictionary located at the specified path within a JSON object. If the subdictionary does not exist, it is created.

Prototype

int kw_set_subdict_value(
    hgobj      gobj,
    json_t     *kw,
    const char *path,
    const char *key,
    json_t     *value // owned
);

Parameters

Key

Type

Description

gobj

hgobj

A handle to the gobj (generic object) that may be used for logging or context.

kw

json_t *

A JSON object where the subdictionary is located.

path

const char *

The path to the subdictionary within kw. The last segment of the path is the subdictionary name.

key

const char *

The key to be set inside the subdictionary.

value

json_t *

The JSON value to be assigned to key. Ownership is transferred to the function.


Return Value

Returns 0 on success, or -1 if an error occurs (e.g., if kw is not a valid JSON object).

Notes

If the subdictionary at path does not exist, it is created as a new JSON object. The function uses kw_get_dict() to retrieve or create the subdictionary.

Prototype

// Not applicable in JS

Prototype

# Not applicable in Python
Examples
// TODO C examples
// TODO JS examples
# TODO Python examples