Free MuleSoft CONNECT Keynote & Expo Pass Available!

Register now+
Nav

write

write(Any, String, Object): Any

Writes input content to a specific format. Specifically, the write function returns a string with the serialized representation of the value in the specified mimeType (format).

The first argument points to the input to write. The second is the format in which to write it. The default is application/dw. A third, optional argument lists writer configuration properties.

See Data Formats Supported by DataWeave for a full list of configuration properties for each format-specific writer.

Transform

        
     
1
2
3
4
5
6
%dw 2.0
output application/xml
---
{
  "output" : write(payload, "application/csv", {"separator" : "|"})
}
Input

        
     
1
2
3
4
5
6
7
8
9
10
11
12
13
14
[
  {
    "Name": "Mr White",
    "Email": "white@mulesoft.com",
    "Id": "1234",
    "Title": "Chief Java Prophet"
  },
  {
    "Name": "Mr Orange",
    "Email": "orange@mulesoft.com",
    "Id": "4567",
    "Title": "Integration Ninja"
  }
]
Output

        
     
1
2
3
4
5
<?xml version='1.0' encoding='US-ASCII'?>
<output>Name|Email|Id|Title
Mr White|white@mulesoft.com|1234|Chief Java Prophet
Mr Orange|orange@mulesoft.com|4567|Integration Ninja
</output>