[PATCH 7/9] util: json: Recursively deflatten objects virJSONValueObjectDeflatten

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.
---
 src/util/virjson.c                          |  8 +++++++-
 tests/virjsondata/deflatten-nested-out.json | 32 +++++++++++++++++++----------
 2 files changed, 28 insertions(+), 12 deletions(-)

diff --git a/src/util/virjson.c b/src/util/virjson.c
index 635b78e3a..0c7beafab 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 acdcd1fc8..f23ed8fd5 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"
+        }
       }
     }
   }
-- 
2.12.2

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]
  Powered by Linux