提交 428d1752 编写于 作者: P Peter Krempa

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.
上级 d40f4b3e
...@@ -1981,7 +1981,13 @@ virJSONValueObjectDeflattenWorker(const char *key, ...@@ -1981,7 +1981,13 @@ virJSONValueObjectDeflattenWorker(const char *key,
/* non-nested keys only need to be copied */ /* non-nested keys only need to be copied */
if (!strchr(key, '.')) { if (!strchr(key, '.')) {
if (!(newval = virJSONValueCopy(value)))
if (virJSONValueIsObject(value))
newval = virJSONValueObjectDeflatten(value);
else
newval = virJSONValueCopy(value);
if (!newval)
return -1; return -1;
if (virJSONValueObjectHasKey(retobj, key)) { if (virJSONValueObjectHasKey(retobj, key)) {
......
{ {
"file": { "file": {
"nest": { "nest": {
"even.objects": "can", "even": {
"even.contain": "some", "objects": "can",
"even.more": { "contain": "some",
"deeply.nested": "objects", "more": {
"deeply.needing": "deflattening", "deeply": {
"deeply.some.even": "more", "nested": "objects",
"deeply.some.than": { "needing": "deflattening",
"others.thought.was": "even", "some": {
"others.thought.completely": "necessary" "even": "more",
}, "than": {
"perhaps": "flat value" "others": {
"thought": {
"was": "even",
"completely": "necessary"
}
}
}
}
},
"perhaps": "flat value"
}
} }
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册