gpt4 book ai didi

java - 震动 : Need to split array and combine with other details

转载 作者:行者123 更新时间:2023-12-01 16:51:32 25 4
gpt4 key购买 nike

我正在尝试使用 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/

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