0

我想将我的 json 数据列表转换为数组

我尝试使用 pluck 和 flatten 但我对表达式感到困惑

我想在json下面转换。这里relatedPartList 和deliverableFileList 来了多次,但我想把它放到一个数组中。

{
"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"
          }]
        }
4

1 回答 1

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 以减少冗长的表达式。

于 2019-07-04T11:24:19.513 回答