From: Michael Tremer Date: Sat, 21 Jun 2025 17:27:20 +0000 (+0000) Subject: json: Add function to add a boolean value X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=4820d9de4f01fae6605a35cae920809e3ace7258;p=pakfire.git json: Add function to add a boolean value Signed-off-by: Michael Tremer --- diff --git a/src/pakfire/json.c b/src/pakfire/json.c index 17c381d8..6c62e3fc 100644 --- a/src/pakfire/json.c +++ b/src/pakfire/json.c @@ -233,6 +233,18 @@ int pakfire_json_add_double(struct json_object* json, const char* name, double v return json_object_object_add(json, name, object); } +int pakfire_json_add_boolean(struct json_object* json, const char* name, int value) { + struct json_object* object = NULL; + + // Make a new boolean value + object = json_object_new_boolean(value); + if (!object) + return -errno; + + // Add the object + return json_object_object_add(json, name, object); +} + int pakfire_json_add_object(struct json_object* json, const char* name, struct json_object** o) { struct json_object* object = NULL; diff --git a/src/pakfire/json.h b/src/pakfire/json.h index a7d192eb..f8d7100f 100644 --- a/src/pakfire/json.h +++ b/src/pakfire/json.h @@ -46,6 +46,7 @@ int pakfire_json_add_stringf(struct json_object* json, const char* name, const c int pakfire_json_add_int64(struct json_object* json, const char* name, int64_t value); int pakfire_json_add_uint64(struct json_object* json, const char* name, uint64_t value); int pakfire_json_add_double(struct json_object* json, const char* name, double value); +int pakfire_json_add_boolean(struct json_object* json, const char* name, int value); int pakfire_json_add_string_array(struct json_object* json, const char* name, char** array); int pakfire_json_add_object(struct json_object* json, const char* name, struct json_object** o); int pakfire_json_add_array(struct json_object* json, const char* name, struct json_object** array);