From: Michael Tremer Date: Sat, 21 Jun 2025 15:53:16 +0000 (+0000) Subject: json: Add a function to convert JSON to string X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ca012356218a29095da3bad8f97df01b66ecb8a4;p=pakfire.git json: Add a function to convert JSON to string Signed-off-by: Michael Tremer --- 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);