Reputation: 115
Input from text file:
ID|ACTION|IID|SPK|DSI|OLID|NLD
1 | M | 1 | 1 | 1 | 1 | 1
Expected output:
{
"source": "PM",
"Timestamp": "4/10/2018 11:44:55 AM",
"tes":{
"id": 1,
"ac": "M",
"test": "1",
"key": "1",
"id": "1",
"nid": "1"
}
}
I tried below code snippet in dataweave but i am getting exception during runtime.
<ee:transform doc:name="Transform Message" doc:id="2a7de32c-1b84-4419-826f-8099ce1dc241" >
<ee:message >
<ee:set-payload ><![CDATA[%dw 2.0
output application/json
input payload text/csv
---
payload map{
source:"PM",
"Timestamp": now() as String {format: "MM/dd/YYYY hh:mm:ss a"},
"tes":{
"id":$.ID,
"action":$.ACTION,
"IID":$.IID,
"SPK":$.SPK,
"DSI":$.DSI,
"OLID":$.OLID,
"NID":$.NLD
}
}
]]></ee:set-payload>
</ee:message>
</ee:transform>
Message : "You called the function 'map' with these arguments: 1: String ("ID|ACTION|IID|SPK|DSI|OLID|NLD...) 2: Function (($:Any, $$:Any) -> ???)
But it expects arguments of these types: 1: Array 2: Function
5| payload map{ | ... 11| }
Trace: at map (line: 5, column: 3) at main (line: 5, column: 11)" evaluating expression: "%dw 2.0 output application/json indent = true input payload text/csv
Upvotes: 0
Views: 2394
Reputation: 25699
In Mule the DataWeave directive input is ignored so it is not useful to set the input mime type. Also you can not set reader properties as in Mule 3. In Mule 4 you should set the mime type and reader properties at the message source as described in the documentatin page: https://docs.mulesoft.com/mule4-user-guide/v/4.1/dataweave-formats#reader_writer_properties Then you can set the separator reader property for the CSV format to a pipe. Other reader properties are described at https://docs.mulesoft.com/mule4-user-guide/v/4.1/dataweave-formats#reader-properties-for-csv
Upvotes: 1