在jolt中是否有其他方法将多个地图集中在一个列表中?



我有一个用例,我需要将这些地图集中在一个列表中。但是不想使用另一个移位操作

有谁能帮我吗?输入JSON

{
"orders": [
{
"orderId": "10001",
"order_parts": [
{
"id": "00001",
"items": [
{
"quantity": 1,
"price": 20
},
{
"quantity": 1,
"price": 20
}
]
},
{
"id": "00004",
"items": [
{
"quantity": 1,
"price": 20
}
]
}
]
}
]
}

预期输出

{
"orderId": "10001",
"order_parts": [
{
"id": "00001",
"items": [
{
"quantity": 1,
"price": 20
},
{
"quantity": 1,
"price": 20
}
]
},
{
"id": "00004",
"items": [
{
"quantity": 1,
"price": 20
}
]
}
],
"totalQuantity": [ 1, 1, 1 ]
}

震动规范

[
{
"operation": "shift",
"spec": {
"orders": {
"*": {
"order_parts": {
"*": {
"items": {
"*": {
"quantity": "[&1].totalQuantity"
}
}
}
},
"@": "[&]"// By this I want to copy input json to be used in the next shift.
}
}
}
},
{
"operation": "shift",
"spec": {
"*": {
"*": "&"
}
}
}
]

现在,我已经使用了另一个移位,但如果不需要使用另一个移位操作,它会对我有所帮助。

任何帮助都将不胜感激。

谢谢。

您可以使用"@": ""的技巧,例如

[
{
"operation": "shift",
"spec": {
"orders": {
"*": {
"order_parts": {
"*": {
"items": {
"*": {
"q*": "totalQ&(0,1)"// the replacement of the zero (current) level literal "uantity" for the first asterisk(which might me multiple)
}
}
}
},
"@": ""
}
}
}
}
]

相关内容

最新更新