From ca012356218a29095da3bad8f97df01b66ecb8a4 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Sat, 21 Jun 2025 15:53:16 +0000 Subject: [PATCH] json: Add a function to convert JSON to string Signed-off-by: Michael Tremer --- src/pakfire/json.c | 6 ++++++ src/pakfire/json.h | 3 +++ 2 files changed, 9 insertions(+) diff --git a/src/pakfire/json.c b/src/pakfire/json.c index bdceb3ba..a7531590 100644 --- a/src/pakfire/json.c +++ b/src/pakfire/json.c @@ -26,6 +26,12 @@ #include #include +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; diff --git a/src/pakfire/json.h b/src/pakfire/json.h index 83bc9058..2023ccd1 100644 --- a/src/pakfire/json.h +++ b/src/pakfire/json.h @@ -27,6 +27,9 @@ #include +// 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); -- 2.47.3