次の問題を解決するために何時間も苦労してきましたが、成功しませんでした。
次のようなデータ構造があります。
[ { 'ROOT': [
{ 'firstElem': 'gc-3/1/0'},
{ 'SecondElem': '5.0.0.1'},
{ 'ThirdElem': '127.3.15.1'},
{ 'index': 16},
{ 'function': 'session'},
{ 'hw': '0.0.0.0'},
{ 'sw': '1.50.1.3'},
{ 'resources': [ { 'cpu-info': [ { 'cpu-peak-load': 1},
{ 'cpu-avg-load': 1}]},
{ 'memory-total': 1},
{ 'memory-used': 2}]},
]},
{ 'ROOT': [
{ 'firstElem': 'gc-4/1/0'},
{ 'SecondElem': '5.0.0.2'},
{ 'ThirdElem': '127.3.4.1'},
{ 'index': 5},
{ 'function': 'stand'},
{ 'hw': '0.0.0.0'},
{ 'sw': '1.50.1.3'},
{ 'resources': [ { 'cpu-info': [ { 'cpu-peak-load': 1},
{ 'cpu-avg-load': 1}]},
{ 'memory-total': 1},
{ 'memory-used': 2}]},
]}
]
このデータ構造をトラバースし、すべての dict-element を同じ名前で結合して、代わりにリストを作成したいと思います。これは説明が難しいので、探している構造の例を作成しました。
{
"ROOT": [
{
"firstElem": "gc-3/1/0",
"SecondElem": "5.0.0.1",
"ThirdElem": "128.0.2.19",
"index": "13",
"function": "session",
"hw": "1.11.0.0 ",
"sw": "1.50.0.228 ",
"resources": {
"cpu-info": {
"cpu-peak-load": "1",
"cpu-avg-load": "1",
},
"memory-total": "1",
"memory-used": "2",
},
},
{
"firstElem": "gc-4/1/0",
"SecondElem": "5.0.0.1",
"ThirdElem": "128.0.2.19",
"index": "13",
"function": "session",
"hw": "1.11.0.0 ",
"sw": "1.50.0.228 ",
"resources": {
"cpu-info": {
"cpu-peak-load": "8",
"cpu-avg-load": "1",
},
"memory-total": "1",
"memory-used": "2",
},
}
],
}
元のデータ構造に固執していて、変更できません。どんな助けでも大歓迎です。上記の構造は単なる例です。データは動的に受信されるため、タグ名はわかりません。そのため、特定のタグ名を使用するソリューションを提供しないでください。