kw_get_str()

kw_get_str()#

Retrieve a string value from a JSON dictionary at the specified path. If the key does not exist, return default_value.

Prototype

const char *kw_get_str(
    hgobj        gobj,
    json_t       *kw,
    const char   *path,
    const char   *default_value,
    kw_flag_t     flag
);

Parameters

Key

Type

Description

gobj

hgobj

Pointer to the GObj instance for logging and error handling.

kw

json_t *

JSON dictionary to search for the string value.

path

const char *

Path to the key in the JSON dictionary.

default_value

const char *

Default string value to return if the key is not found.

flag

kw_flag_t

Flags to control behavior, such as KW_REQUIRED for logging errors if the key is missing.


Return Value

Returns the string value associated with path in kw. If the key does not exist, returns default_value. If KW_EXTRACT is set, the key is removed from kw.

Notes

If the value at path is not a string, an error is logged, and default_value is returned. The function does not duplicate the returned string, so it should not be modified.

Prototype

// Not applicable in JS

Prototype

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