From: Peter Krempa Date: Mon, 26 Jun 2017 17:37:18 +0000 (+0200) Subject: util: json: Recursively deflatten objects virJSONValueObjectDeflatten X-Git-Tag: v3.6.0-rc1~253 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=428d175206ebe12be39fcac730ecf509fb806154;p=thirdparty%2Flibvirt.git util: json: Recursively deflatten objects virJSONValueObjectDeflatten If a value of the first level object contains more objects needing deflattening which would be wrapped in an actual object the function would not recurse into them. By this simple addition we can fully deflatten the objects. --- diff --git a/src/util/virjson.c b/src/util/virjson.c index 665278b0aa..17b11f2b3d 100644 --- a/src/util/virjson.c +++ b/src/util/virjson.c @@ -1981,7 +1981,13 @@ virJSONValueObjectDeflattenWorker(const char *key, /* non-nested keys only need to be copied */ if (!strchr(key, '.')) { - if (!(newval = virJSONValueCopy(value))) + + if (virJSONValueIsObject(value)) + newval = virJSONValueObjectDeflatten(value); + else + newval = virJSONValueCopy(value); + + if (!newval) return -1; if (virJSONValueObjectHasKey(retobj, key)) { diff --git a/tests/virjsondata/deflatten-nested-out.json b/tests/virjsondata/deflatten-nested-out.json index acdcd1fc8c..f23ed8fd56 100644 --- a/tests/virjsondata/deflatten-nested-out.json +++ b/tests/virjsondata/deflatten-nested-out.json @@ -1,17 +1,27 @@ { "file": { "nest": { - "even.objects": "can", - "even.contain": "some", - "even.more": { - "deeply.nested": "objects", - "deeply.needing": "deflattening", - "deeply.some.even": "more", - "deeply.some.than": { - "others.thought.was": "even", - "others.thought.completely": "necessary" - }, - "perhaps": "flat value" + "even": { + "objects": "can", + "contain": "some", + "more": { + "deeply": { + "nested": "objects", + "needing": "deflattening", + "some": { + "even": "more", + "than": { + "others": { + "thought": { + "was": "even", + "completely": "necessary" + } + } + } + } + }, + "perhaps": "flat value" + } } } }