如何在 Jolt 轉換 JSON 陣列中保留其他欄位,我正在嘗試使用通配符但最終輸出中未添加欄位?
這是我正在使用的示例輸入
[
{
"foundduring": "D-DC",
"user_type": "type1",
"location": "location1"
},
{
"foundduring": "D-DG",
"user_type": "type2",
"location": "location2"
},
{
"foundduring": "D-DI",
"user_type": "type3",
"location": "location3"
}
]
我正在使用以下 Jolt 轉換并嘗試使用通配符:
[
{
"operation": "shift",
"spec": {
"*": {
"foundduring": {
"D-DC": {
"#CycleCount": "[&3].foundduring"
},
"D-DG": {
"#Pick": "[&3].foundduring"
},
"D-DI": {
"#Issue": "[&3].foundduring"
}
},
"@": "&"
}
}
}
]
以下是發生移位操作的預期輸出,然后需要保留所有其他欄位
[
{
"foundduring" : "CycleCount",
"user_type" : "type1",
"location" : "location1"
},
{
"foundduring" : "Pick",
"user_type" : "type2",
"location" : "location2"
},
{
"foundduring" : "Issue",
"user_type" : "type3",
"location" : "location3"
}
]
實際輸出:
[
{
"foundduring": "CycleCount"
},
{
"foundduring": "Pick"
},
{
"foundduring": "Issue"
}
]
uj5u.com熱心網友回復:
考慮使用"*"通配符作為else case而不是"@"諸如
[
{
"operation": "shift",
"spec": {
"*": {
"foundduring": {
"D-DC": {
"#CycleCount": "[&3].&2"
},
"D-DG": {
"#Pick": "[&3].&2"
},
"D-DI": {
"#Issue": "[&3].&2"
}
},
"*": "[&1].&"
}
}
}
]
順便說一句,不需要獲取鍵名"foundduring",只需使用&2替換從當前分支升級 2 級并獲取該值。
網站
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/463819.html
上一篇:pythonJSONfor回圈
