0
votes

A quick question, in HTTP POST body I am passing a table details with columns. Here columns element is an array. I want to fetch the entire array.

I am using mule 4

Eg:

  {
  "TableName": "Customer",
  "Columns": ["ID","Name"]
}

Expected Output: In a variable both columns: (ID, Name)

How can this be achieved?

Thanks in advance

1

1 Answers

0
votes

To get value you just mention it in the Transformation. Like this

%dw 2.0
var x={
  "TableName": "Customer",
  "Columns": ["ID","Name"]
}
output application/json
---
{
    array:x.Columns
}

result:

{
  "array": [
    "ID",
    "Name"
  ]
}

enter image description here

If you want to grab value from your POST payload then it should be like this:

        <ee:transform doc:name="Transform Message" >
            <ee:message>
            </ee:message>
            <ee:variables >
                <ee:set-variable variableName="myArray" ><![CDATA[%dw 2.0
output application/java
---
payload.Columns]]></ee:set-variable>
            </ee:variables>
        </ee:transform>