Extract the code so that there's a clean separation once we'll want do do other steps. Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx> --- src/util/virjson.c | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/src/util/virjson.c b/src/util/virjson.c index f308927fa0..65d6521789 100644 --- a/src/util/virjson.c +++ b/src/util/virjson.c @@ -2049,6 +2049,10 @@ virJSONStringReformat(const char *jsonstr, } +static virJSONValuePtr +virJSONValueObjectDeflattenKeys(virJSONValuePtr json); + + static int virJSONValueObjectDeflattenWorker(const char *key, virJSONValuePtr value, @@ -2064,7 +2068,7 @@ virJSONValueObjectDeflattenWorker(const char *key, if (!strchr(key, '.')) { if (virJSONValueIsObject(value)) - newval = virJSONValueObjectDeflatten(value); + newval = virJSONValueObjectDeflattenKeys(value); else newval = virJSONValueCopy(value); @@ -2113,6 +2117,20 @@ virJSONValueObjectDeflattenWorker(const char *key, } +static virJSONValuePtr +virJSONValueObjectDeflattenKeys(virJSONValuePtr json) +{ + g_autoptr(virJSONValue) deflattened = virJSONValueNewObject(); + + if (virJSONValueObjectForeachKeyValue(json, + virJSONValueObjectDeflattenWorker, + deflattened) < 0) + return NULL; + + return g_steal_pointer(&deflattened); +} + + /** * virJSONValueObjectDeflatten: * @@ -2128,12 +2146,5 @@ virJSONValueObjectDeflattenWorker(const char *key, virJSONValuePtr virJSONValueObjectDeflatten(virJSONValuePtr json) { - g_autoptr(virJSONValue) deflattened = virJSONValueNewObject(); - - if (virJSONValueObjectForeachKeyValue(json, - virJSONValueObjectDeflattenWorker, - deflattened) < 0) - return NULL; - - return g_steal_pointer(&deflattened); + return virJSONValueObjectDeflattenKeys(json); } -- 2.24.1