我正在尝试使用 JOLT 进行 JSON 转换。 但我陷入了分割 JSON 数组并附加其他详细信息的位置 如当前输出中所示,我能够提取第 0 个值并附加详细信息,但如何提取下一个元素并附加 OfferId。
输入 JSON
{
"count": 100,
"data": [
{
"offerDetails": {
"offerId": "1234"
},
"merchantDetails": {
"merchantName": "merchantName",
"merchantLocations": [
{
"merchantAddress": "merchantAddress1"
},
{
"merchantAddress": "merchantAddress2"
}
]
}
}
]
}
以下是我尝试过的规范
[
{
"operation": "shift",
"spec": {
"data": {
"*": {
"offerDetails": {
"offerId": "offerId"
},
"merchantDetails": {
"merchantLocations": {
"0": {
"merchantAddress": "merchant.name"
}
}
}
}
}
}
}
]
电流输出
{
"offerId" : "1234",
"merchant" : {
"name" : "merchantAddress1"
}
}
期望的输出
[{
"offerId": "1234",
"merchant": {
"name": "merchantAddress1"
}
},
{
"offerId": "1234",
"merchant": {
"name": "merchantAddress2"
}
}
]
最佳答案
这会有所帮助,
遍历merchantLocations
获取商家名称,并从merchantLocations
向后移动直到offerId
[
{
"operation": "shift",
"spec": {
"data": {
"*": {
"merchantDetails": {
"merchantLocations": {
"*": {
"@(3,offerDetails.offerId)": "[].offerId",
"merchantAddress": "[&1].merchant.name"
}
}
}
}
}
}
}
]
关于java - 震动 : Need to split array and combine with other details,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61676420/