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.

Official exam objective
Convert between output types and data types using DataWeave.

~8 min read · 6 practice questions ·

What the exam expects

  • Write the output directive that selects the right writer (JSON, CSV, XML, Java) and append writer properties such as the CSV separator and header or the JSON skipNullOn.
  • Report a custom MIME type such as application/problem+json while a standard writer formats the body, using with.
  • Tell reader properties (on a listener or Read operation's outputMimeType) from writer properties (on the output directive), 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 output directive, 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 json works as well as output application/json
Custom MIME type
Detail
output application/problem+json with json: MIME type first, writer after with
HTTP Content-Type
Detail
HTTP uses the script's MIME type to generate its Content-Type header
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=true for 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 a java.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)
  • 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 with in its output directive?
  • What does <set-payload value="#[{a: true}]"/> produce?
  • Which skipNullOn value removes nulls from both objects and arrays?
  • Why is output application/dw kept 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

Practice for the MuleSoft Developer exam