]> git.ipfire.org Git - people/ms/pakfire.git/commitdiff
json: Add a function to convert JSON to string
authorMichael Tremer <michael.tremer@ipfire.org>
Sat, 21 Jun 2025 15:53:16 +0000 (15:53 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 21 Jun 2025 15:53:16 +0000 (15:53 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/pakfire/json.c
src/pakfire/json.h

index bdceb3baf5f4888aa901272c8def1ea3a47d20b3..a753159013c75789cdbede85c0613af7d1afb7ce 100644 (file)
 #include <pakfire/logging.h>
 #include <pakfire/util.h>
 
+const char* pakfire_json_to_string(struct json_object* json) {
+       const int flags = JSON_C_TO_STRING_SPACED | JSON_C_TO_STRING_PRETTY;
+
+       return json_object_to_json_string_ext(json, flags);
+}
+
 struct json_object* pakfire_json_parse(
                struct pakfire_ctx* ctx, const char* buffer, const size_t length) {
        struct json_tokener* tokener = NULL;
index 83bc9058ce41d3bbaed3cece23f9126a2071d820..2023ccd1fdbf2d304d6738e772bb8242c3f44205 100644 (file)
@@ -27,6 +27,9 @@
 
 #include <pakfire/ctx.h>
 
+// To String
+const char* pakfire_json_to_string(struct json_object* json);
+
 // Parse
 struct json_object* pakfire_json_parse(struct pakfire_ctx* ctx,
        const char* buffer, const size_t length);