我想将我的json数据列表转换为数组
我尝试使用pluck和flatten,但是我对表达式感到困惑
我想在json下面转换。这里relatedPartList和deliveryableFileList会多次出现,但我想将其放入数组中。
{
"documentRevisionList": {
"entityId": "854598400000480352532DA50006EFDB",
"deleted": "false",
"revision": "A",
"revisionSequenceNumber": "0",
"latestRevision": "true",
"title": "PC FOR EBIZ TESTING",
"status": "Active",
"relatedPartList":
{
"tcpn": "145154-1",
"partRevision": "K",
"relationshipVerified": "true"
},
"relatedPartList": {
"tcpn": "271598-000",
"partRevision": "O",
"relationshipVerified": "true"
},
"relatedPartList": {
"tcpn": "825281-000",
"partRevision": "O",
"relationshipVerified": "true"
},
"deliverableFileList": {
"entityId": "854598400000480352532E3B000760FE",
"url": "https://dmtecdev.us.tycoelectronics.com/dmtec/documentDelivery/getFile?deliverableId=854598400000480352532E3B000760FE",
"fileName": "ENG_PC_10072013-2_A_PC.pdf",
"fileLanguage": "English",
"fileType": "pdf",
"fileSize": "13631",
"fileAttached": "true"
},
"deliverableFileList": {
"entityId": "000000000000F4E6561BFAB600055FA1",
"url": "https://dmtecdev.us.tycoelectronics.com/dmtec/documentDelivery/getFile?deliverableId=000000000000F4E6561BFAB600055FA1",
"fileName": "ENG_PC_10072013-2_A(830530).docx",
"fileLanguage": "English",
"fileType": "docx",
"fileSize": "12969",
"fileAttached": "true"
}
}
}
我想要这种类型的回复
"documentRevisionList": {
"entityId": "854598400000480352532DA50006EFDB",
"deleted": "false",
"revision": "A",
"revisionSequenceNumber": "0",
"latestRevision": "true",
"title": "PC FOR EBIZ TESTING",
"status": "Active",
"relatedPartList":
[
{
"tcpn": "145154-1",
"partRevision": "K",
"relationshipVerified": "true"
},
{
"tcpn": "271598-000",
"partRevision": "O",
"relationshipVerified": "true"
},
{
"tcpn": "825281-000",
"partRevision": "O",
"relationshipVerified": "true"
}
]
"deliverableFileList": [{
"entityId": "854598400000480352532E3B000760FE",
"url": "https://dmtecdev.us.tycoelectronics.com/dmtec/documentDelivery/getFile?deliverableId=854598400000480352532E3B000760FE",
"fileName": "ENG_PC_10072013-2_A_PC.pdf",
"fileLanguage": "English",
"fileType": "pdf",
"fileSize": "13631",
"fileAttached": "true"
},
{
"entityId": "000000000000F4E6561BFAB600055FA1",
"url": "https://dmtecdev.us.tycoelectronics.com/dmtec/documentDelivery/getFile?deliverableId=000000000000F4E6561BFAB600055FA1",
"fileName": "ENG_PC_10072013-2_A(830530).docx",
"fileLanguage": "English",
"fileType": "docx",
"fileSize": "12969",
"fileAttached": "true"
}]
}
答案 0 :(得分:0)
这似乎是使用*选择器的简单情况。
%dw 2.0
output application/json
---
{
documentRevisionList: {
entityId: payload.documentRevisionList.entityId,
deleted: payload.documentRevisionList.deleted,
...
relatedPartList: payload.documentRevisionList.*relatedPartList,
deliverableFileList: payload.documentRevisionList.*deliverableFileList
}
}
要点:您可以将变量设置为payload.documentRevisionList,以减少冗长的表达式。