在颠簸转换后,我需要得到低于json期望值的响应,但我要为orderId,subId字段获取数组,我想将其作为orderItemId的单独对象的一部分。如果以下规格有任何问题,请您帮我。我尽力找到一个解决方案,但未能做到。请帮忙。
JsonInput:
{
"Employees": {
"employees": [
{
"employeeDetails": [
{
"productName": "Iphone 7 Plus",
"actionType": "ADD_PHONE",
"status": "DELIVERY",
"subId": "sub1",
"id": "920040222"
}
],
"status": "SUBMITTED",
"id": "920040221",
"currency": "USD"
},
{
"employeeDetails": [
{
"productName": "Iphone 7 Plus",
"actionType": "ADD_PHONE",
"status": "DELIVERY",
"subId": "sub2",
"id": "920040224"
},
{
"productName": "Iphone 8 Plus",
"actionType": "ADD_PHONE",
"status": "DELIVERY",
"subId": "sub3",
"id": "920040225"
}
],
"status": "SUBMITTED",
"id": "920040223",
"currency": "USD"
}
]
}
}
震动规格:
[
{
"operation": "shift",
"spec": {
"Employees": {
"employees": {
"*": {
"employeeDetails": {
"*": {
"actionType": {
"ADD_PHONE": {
"@(2,productName)": {
"Iphone 7 Plus|Iphone 8 Plus": {
"@(4,status)": {
"*": {
"@(6,id)": "ids[].itemId",
"@(8,id)": "ids[&9].orderId",
"@(6,subId)": "ids[&9].subId"
}
}
}
}
}
}
}
}
}
}
}
}
}
]
实际输出:
{
"ids" : [ {
"itemId" : "920040222",
"orderId" : "920040221",
"subId" : "sub1"
}, {
"itemId" : "920040224",
"orderId" : [ "920040223", "920040223" ],
"subId" : [ "sub2", "sub3" ]
}, {
"itemId" : "920040225"
} ]
}
预期输出:
{
"ids" : [ {
"itemId" : "920040222",
"orderId" : "920040221",
"subId" : "sub1"
}, {
"itemId" : "920040224",
"orderId" : "920040223",
"subId" : "sub2"
}, {
"itemId" : "920040225",
"orderId" : "920040223",
"subId" : "sub3"
}]
}
答案 0 :(得分:0)
您必须将数组保留在数组中,然后将其转换为所需的输出:
[
{
"operation": "shift",
"spec": {
"Employees": {
"employees": {
"*": {
"employeeDetails": {
"*": {
"actionType": {
"ADD_PHONE": {
"@(2,productName)": {
"Iphone 7 Plus|Iphone 8 Plus": {
"@(4,status)": {
"*": {
"@(6,id)": "[&9].[&7].itemId",
"@(8,id)": "[&9].[&7].orderId",
"@(6,subId)": "[&9].[&7].subId"
}
}
}
}
}
}
}
}
}
}
}
}
},
{
"operation": "shift",
"spec": {
"*": {
"*": "ids.[]"
}
}
}
]