Transforming Data10% of the exam
DataWeave output formats, readers and writers
How the output directive picks a DataWeave writer and MIME type, how `with` reports a custom MIME type such as application/problem+json, where reader properties (on a source's outputMimeType) and writer properties (on the output directive) go, how CSV input is represented, and which writer DataWeave uses when a script has no output directive.
Convert between output types and data types using DataWeave.
~8 min read · 6 practice questions ·
What the exam expects
- Write the
outputdirective that selects the right writer (JSON, CSV, XML, Java) and append writer properties such as the CSVseparatorandheaderor the JSONskipNullOn. - Report a custom MIME type such as
application/problem+jsonwhile a standard writer formats the body, usingwith. - Tell reader properties (on a listener or Read operation's
outputMimeType) from writer properties (on theoutputdirective), and predict what each one changes. - Predict how CSV input is represented in DataWeave and what a JSON writer prints for it.
- Predict the data type of an expression that has no
outputdirective, such as a literal in Set Payload. - Key terms: output directive (header line that names the output MIME type or format ID); writer (format-specific serializer of the script's result); reader (format-specific parser of an input); reader/writer properties (format-specific settings appended to a MIME type or directive); format ID (short name such as
json,csv,java); TypedValue (Mule's value plus data type, i.e. MIME type and encoding).
Key facts
Format ID in the directive
- Detail
- Since Mule 4.3.0,
output jsonworks as well asoutput application/json
Custom MIME type
- Detail
output application/problem+json with json: MIME type first, writer afterwith
HTTP Content-Type
- Detail
- HTTP uses the script's MIME type to generate its
Content-Typeheader
CSV writer defaults
- Detail
separator=,,header=true,quoteValues=false
CSV values
- Detail
- Read as Strings; rows are objects keyed by the header
CSV reader memory
- Detail
- In memory up to 1.5 MB, on disk above;
streaming=truefor sequential access
skipNullOn values- Detail
arrays,objects,everywhere; default skips nothing
Reader properties
- Detail
- Appended to a listener's or Read operation's
outputMimeType; never transform
No input, no directive
- Detail
- Java writer;
#[{a: true}]becomes ajava.util.Map
Mixed input types
- Detail
- Inputs of different data types with no directive throw an error
dw format- Detail
- Canonical debug format; significantly slower, not for production
Sources for this section (6)
- Supported Data Formatsdocs.mulesoft.com (opens in a new tab)
- Change a Script's MIME Type Outputdocs.mulesoft.com (opens in a new tab)
- CSV Formatdocs.mulesoft.com (opens in a new tab)
- JSON Formatdocs.mulesoft.com (opens in a new tab)
- Mule Data Typesdocs.mulesoft.com (opens in a new tab)
- DataWeave (dw) Formatdocs.mulesoft.com (opens in a new tab)
- When does the CSV reader keep a file on disk instead of in memory, and what lets you stream it?
- When should a script use
within its output directive? - What does
<set-payload value="#[{a: true}]"/>produce? - Which
skipNullOnvalue removes nulls from both objects and arrays? - Why is
output application/dwkept out of production flows?
The questions are free to read. Answers with their sources and self-grading are included with the pack.
Keep reading with the MuleSoft Developer pack
- Core concepts
- Exam traps
- Worked scenario
The pack includes:
- All 40 lessons of the MuleSoft Developer guide, with reading progress
- Interactive decision walks and step-by-step sequence steppers
- Practice exams purchase adds inline bank questions and topic practice (6 questions for this lesson)
- An official source cited for every claim
- An AI tutor that answers from the guide
- Unlimited timed practice exams