Search code examples
mulexlsxmule-studiomule-componentdataweave

Mulesoft dataweave: How to convert xlsx file to JSON by including headers?


I am trying convert xlsx to json with dataweave. JSON output is getting generated without headers from the xlsx file. My current code is skipping fisrt row of an excel file. I also need to include firstrow from the input file to output JSON. Below is my dataweave:

<dw:transform-message doc:name="Transform Message" metadata:id="8211af7d-2465-4ecd-80ea-3b6771d094e5">
<dw:input-payload mimeType="application/xlsx"/>
<dw:set-payload><![CDATA[%dw 1.0
%output application/json
---
{
    Sheet1:payload.Sheet1 map
    {
        col1:$[0],
        col2:$[1],
        col3:$[2]
    },

    Sheet2:payload.Sheet2 map
    {
        col1:$[0],
        col2:$[1],
        col3:$[2]
    }
}]]></dw:set-payload>
</dw:transform-message>

Input Excel file is as:

Total Value Count

Col1 Col2 Col3

Val Val Val


Solution

  • I was able to figure it out by adding below code to my xml:

    <dw:input-payload mimeType="application/xlsx"> 
                    <dw:reader-property name="header" value="false" />
     </dw:input-payload>
    

    This worked for my requirement.