我在使用Jolt变换获得所需输出时遇到了麻烦.
我的输入JsonArray看起来像这样:
[
{
"from": [
{
"area1": 1
},
{
"area2": 1
},
{
"area3": 1
}
],
"id": 111,
"to": "destination1"
},
{
"from": [
{
"area1": 2
},
{
"area2": 2
},
{
"area3": 2
}
],
"id": 222,
"to": "destination2"
}
]
我正在使用Jolt Spec为JsonArray中的每个JsonObject创建一个JsonArray "from",并希望包含where "id"和"to"键:
[
{
"operation": "shift",
"spec": {
"*": {
"from": {
"*": {
"@": "[&]",
"@(2,id)": "[&].id",
"@(2,to)": "[&].to"
}
}
}
}
}
]
这是输出:
[
[
{
"area1": 1,
"id": 111,
"to": "destination1"
},
{
"area1": 2
}
],
[
{
"area2": 1,
"id": 111,
"to": "destination1"
},
{
"area2": 2
}
],
[
{
"area3": 1,
"id": 111,
"to": "destination1"
},
{
"area3": 2
}
]
]
我想要的输出应该是这样的:
[
{
"area1": 1,
"id": 111,
"to": "destination1"
},
{
"area1": 2,
"id": 222,
"to": "destination2"
},
{
"area2": 1,
"id": 111,
"to": "destination1"
},
{
"area2": 2,
"id": 222,
"to": "destination2"
},
{
"area3": 1,
"id": 111,
"to": "destination1"
},
{
"area3": 2,
"id": 222,
"to": "destination2"
}
]
我不知道为什么输入的第二个JSON Object中没有包含"id"和"to"键. 有没有人知道如何修复Jolt以获得所需的输出?