Search code examples
jsonmuledataweavemule-esb

JSON array into line using mule dataweave


I have the below requirement.

Input is

{ "packageConfiguration": [
      {
        "packageId": [
          "AIM_PACKAGE"
        ],
        "component": [
          "Handbook"
        ],
        "fieldName": [
          "Upload Handbook Document"
        ],
        "assetUrl": [
          "sflydamlocation.handbookfilename.pdf"
        ]
      }
    ]}

I need to convert above json array into this output format:

 {
        "pakage": ""packageId":"AIM_PACKAGE", "component":"Handbook",  "fieldName":"Upload Handbook Document","assetUrl":"sflydamlocation.handbookfilename.pdf""
}

Solution

  • Something like this should work, unless you require something more flexible. I'm assuming you're working w/ Mule3/DW1:

    %dw 1.0
    %output application/json
    
    %var packageConfig = payload.packageConfiguration[0]
    ---
    {
      package: packageConfig mapObject ((value, key) -> {
        (key): value[0]
      })
    }