gpt4 book ai didi

java - Jolt 转换 JSON 数组保留其余字段

转载 作者:行者123 更新时间:2023-12-05 04:30:39 26 4
gpt4 key购买 nike

如何在 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"
}
]

最佳答案

考虑使用 "*" 通配符作为 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 级并获取该值。

网站上的演示 http://jolt-demo.appspot.com/

enter image description here

关于java - Jolt 转换 JSON 数组保留其余字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71991486/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com