我需要使用带有insuredId的jolt框架删除json消息中的重复项,并将唯一的insuredId和insuredName分别复制到namecode和name,我已经实现了使用insuredId删除重复但我不知道如何复制相应的保险名称随之而来。
输入:
[
{
"aircraftId": "ILTA",
"aircraftTypeCode": "",
"insuredId": "12020671",
"insuredName": "Samuel Antony",
"policyReference": "20081238",
"uwy": "2017"
},
{
"aircraftId": "ILTA",
"aircraftTypeCode": "",
"insuredId": "12020671",
"insuredName": "Samuel Antony",
"policyReference": "20081238",
"uwy": "2017"
},
{
"aircraftId": "ADE",
"aircraftTypeCode": "",
"insuredId": "12018832",
"insuredName": "Mark henry",
"policyReference": "20082780",
"uwy": "2017"
}
]
Jolt Spec:
[
{
"operation": "shift",
"spec": {
"*": {
"insuredId": {
"*": "ids.&[]"
}
}
}
},
{
"operation": "shift",
"spec": {
"ids": {
"*": {
"$": "[#2].nameCode"
}
}
}
}
]
实际输出:
[
{
"nameCode": "12020671"
},
{
"nameCode": "12018832"
}
]
预期产出:
[
{
"nameCode": "12020671",
"name":"Samuel Antony"
},
{
"nameCode": "12018832",
"name":"Mark henry"
}
]
更新的规范(需要验证):
[
{
"operation": "shift",
"spec": {
"*": {
"insuredId": {
"*": "ids.&[]"
},
"insuredName": {
"*": "insuredNames.&[]"
}
}
}
},
{
"operation": "shift",
"spec": {
"ids": {
"*": {
"$": "[#2].nameCode"
}
},
"insuredNames": {
"*": {
"$": "[#2].name"
}
}
}
}
]
答案 0 :(得分:0)
[
{
"operation": "shift",
"spec": {
"*": {
"insuredId": {
"*": {
"@(2,insuredName)": "ids.&[]"
}
}
}
}
},
{
"operation": "shift",
"spec": {
"ids": {
"*": {
"$": "[#2].nameCode",
"*": "[#2].name"
}
}
}
},
{
"operation": "modify-overwrite-beta",
"spec": {
"*": {
"name": "=firstElement(@(1,name))"
}
}
}
]
解释
第一次操作:
[
{
"operation": "shift",
"spec": {
"*": {
"insuredId": {
"*": {
"@(2,insuredName)": "ids.&[]"
}
}
}
}
}
]
它收集有" insuredId"作为" insuredName"的关键和列表作为价值观:
{
"ids" : {
"12020671" : [ "Samuel Antony", "Samuel Antony" ],
"12018832" : [ "Mark henry" ]
}
}
第二次操作:
[
{
"operation": "shift",
"spec": {
"ids": {
"*": {
"$": "[#2].nameCode",
"*": "[#2].name"
}
}
}
}
]
它将地图转换为简单的对列表:
[ {
"nameCode" : "12018832",
"name" : "Mark henry"
}, {
"nameCode" : "12020671",
"name" : [ "Samuel Antony", "Samuel Antony" ]
} ]
第三次操作:
[
{
"operation": "modify-overwrite-beta",
"spec": {
"*": {
"name": "=firstElement(@(1,name))"
}
}
}
]
它需要包含名称的数组的第一个元素:
[ {
"nameCode" : "12018832",
"name" : "Mark henry"
}, {
"nameCode" : "12020671",
"name" : "Samuel Antony"
} ]
答案 1 :(得分:0)
您可以使用四个连续的shift变换。 在第一步中单独选择每个所需的键,以便为每个键获得两个列表。在第二步中使每个列表中的元素都是唯一的。在这一步中,我们有两个带键的对象。然后再次将它们转换为列表。并根据每个列表中的索引将它们分组到没有键的对象中,例如
[
{
"operation": "shift",
"spec": {
"*": {
"insuredId": "&",
"insuredName": "&"
}
}
},
{
"operation": "shift",
"spec": {
"*": {
"*": {
"*": "&2.&"
}
}
}
},
{
"operation": "shift",
"spec": {
"*": {
"*": {
"$": "&2"
}
}
}
},
{
"operation": "shift",
"spec": {
"*": {
"*": "[&].&1"
}
}
}
]