kw_clone_by_keys()

kw_clone_by_keys()#

The function kw_clone_by_keys() returns a new JSON object containing only the keys specified in keys. The keys can be provided as a string, a list of strings, or a dictionary where the keys are the desired fields. If keys is empty, the original JSON object is returned.

Prototype

json_t *kw_clone_by_keys(
    hgobj   gobj,
    json_t *kw,     // owned
    json_t *keys,   // owned
    BOOL    verbose
);

Parameters

Key

Type

Description

gobj

hgobj

A handle to the GObj (Generic Object) system, used for logging and error handling.

kw

json_t *

The JSON object to be filtered. This parameter is owned and will be decremented.

keys

json_t *

A JSON object specifying the keys to retain. It can be a string, a list of strings, or a dictionary. This parameter is owned and will be decremented.

verbose

BOOL

If TRUE, logs an error when a specified key is not found in kw.


Return Value

A new JSON object containing only the specified keys. If keys is empty, the original kw is returned. The caller owns the returned JSON object.

Notes

If keys is a dictionary or list, only the keys present in keys will be retained in the returned JSON object. If verbose is enabled, missing keys will be logged as errors.

Prototype

// Not applicable in JS

Prototype

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