我需要构造数组并将其附加到现有数组中。
我的输入json是:
{
"restaurantId": "ZZ4ORJDY3E",
"chainId": "RLR932KI",
"orderItems": [
{
"itemName": "Small Barqs",
"quantity": 2
},
{
"itemName": "Mozzz",
"quantity": 1
}
]
}
而且,我试图将输出显示为:
{
"array" : [ {
"field1" : "RLR932KI",
"field2" : "ZZ4ORJDY3E"
}, {
"field1" : "Small Barqs",
"field2" : 2
}, {
"field1" : "Mozzz",
"field2" : 1
} ]
}
我现在拥有的规格:
[
{
"operation": "shift",
"spec": {
"chainId": "array[0].field1",
"restaurantId": "array[0].field2",
"orderItems": {
"*": {
"itemName": "array[&1].field1",
"quantity": "array[&1].field2"
}
}
}
}
]
以上规格给我:
{
"array" : [ {
"field1" : [ "RLR932KI", "Small Barqs" ],
"field2" : [ "ZZ4ORJDY3E", 2 ]
}, {
"field1" : "Mozzz",
"field2" : 1
} ]
}
答案 0 :(得分:0)
这可以通过两阶段转换来实现:
[
{
"operation": "shift",
"spec": {
//create array arrays
"chainId": "[0].[0].field1",
"restaurantId": "[0].[0].field2",
"orderItems": {
"*": {
"itemName": "[1].[&1].field1",
"quantity": "[1].[&1].field2"
}
}
}
},
{
"operation": "shift",
"spec": {
//flatten array of arrays
"*": {
"*": "array.[]"
}
}
}
]