我想使用 JOLT Transform 將字典轉換為 JSON 物件。下面我用下面的例子來演示它。
根目錄中有一個陣列,其中包含來自不同計算機的結果。“計算機 1”、“計算機 2”等。
這個結構應該保留。我洗掉了第二個和更多的陣列元素,它將以與{...}.
給定物件:
[
{
"name": "Computer1",
"events": {
"counts": [
{
"countType": "CRITICAL",
"count": 5
},
{
"countType": "HIGH",
"count": 12
},
{
"countType": "LOW",
"count": 40
}
]
},
"processes": {
"counts": [
{
"countType": "CRITICAL",
"count": 0
},
{
"countType": "HIGH",
"count": 2
},
{
"countType": "LOW",
"count": 80
}
]
}
},
{
"name": "Computer2",
"events": {...},...
}
]
期望的輸出:
[
{
"name": "Computer1",
"events": {
"CRITICAL": 5,
"HIGH": 12,
"LOW": 40
},
"processes": {
"CRITICAL": 0,
"HIGH": 2,
"LOW": 80
}
}
, {
"name": "Computer2",
"events": {...},
...
}
]
請幫助確定正確的 JOLT 規格。
在此先感謝馬庫斯
uj5u.com熱心網友回復:
您可以使用這樣的移位轉換規范
[
{
"operation": "shift",
"spec": {
"*": {
"name": "&1.&",
"events|processes": { // pipe represents "OR" logic
"counts": {
"*": {
"@count": "&4.&3.@countType" // "&4" and "&3" represent going four and three level up the tree to grab the indices of the outermost level list and the key name of the objects("events" and "processes") respectively
}
}
}
}
}
},
{
"operation": "shift",
"spec": {
"*": ""
}
}
]
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/465323.html
下一篇:Jsoncpp嵌套物件陣列
