]> git.ipfire.org Git - pakfire.git/commitdiff
json: Add a convenience function to append strings to arrays
authorMichael Tremer <michael.tremer@ipfire.org>
Sat, 8 Feb 2025 18:01:28 +0000 (18:01 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 8 Feb 2025 18:01:28 +0000 (18:01 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/pakfire/json.c
src/pakfire/json.h

index b9ad764db835f95b28ee61fe65a3a525bbfaeab2..ded6663c85a4db28f0f7a248bb0119dea5431538 100644 (file)
@@ -235,6 +235,15 @@ int pakfire_json_add_array(struct json_object* json, const char* name, struct js
        return json_object_object_add(json, name, object);
 }
 
+int pakfire_json_array_add_string(struct json_object* array, const char* s) {
+       // Make a new string object
+       struct json_object* object = json_object_new_string_len(s, strlen(s));
+       if (!object)
+               return -errno;
+
+       return json_object_array_add(array, object);
+}
+
 static int __pakfire_json_get_object(struct json_object* json,
                const char* key, const json_type type, struct json_object** o) {
        struct json_object* object = NULL;
index 6dfcb682876351d4cea6e4fc01f6722b51f85a42..438398c0c49cc238892bbdb24529ac7d7a9b8bb1 100644 (file)
@@ -47,6 +47,8 @@ int pakfire_json_add_string_array(struct json_object* json, const char* name, ch
 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);
 
+int pakfire_json_array_add_string(struct json_object* array, const char* s);
+
 int pakfire_json_get_string(struct json_object* json, const char* key, const char** value);
 int pakfire_json_get_int64(struct json_object* json, const char* key, int64_t* value);
 int pakfire_json_get_object(struct json_object* json, const char* key, struct json_object** object);