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.
This commit is contained in:
Peter Krempa 2017-06-26 19:37:18 +02:00
parent d40f4b3e67
commit 428d175206
2 changed files with 28 additions and 12 deletions

View File

@ -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)) {

View File

@ -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"
}
}
}
}