Transforming Data10% of the exam

Coercing, formatting, ordering and filtering in DataWeave

How the `as` operator coerces values with format, locale and mode properties, which date pattern letters mean what (uuuu, MM, dd, D, mm), how relational and equality operators coerce mixed types, how orderBy sorts ascending and how to reverse it, and when to use filter versus filterObject.

Official exam objective
Apply correct syntax to write DataWeave transformations to coerce, format, order, and filter data, and predict outcomes.

~7 min read · 9 practice questions ·

What the exam expects

  • Coerce values with as, adding format, locale or mode properties, and predict the resulting type and text.
  • Parse a non-ISO date string with the matching input pattern, then write it in another pattern, choosing the right letters (uuuu, yyyy, MM, dd, D, mm).
  • Predict comparisons between mixed types ("12" > 8, "true" == true) and fix them with as or ~=.
  • Sort with orderBy, reverse the order for descending results, and predict orderBy on an object.
  • Filter arrays with filter (item and index) and objects with filterObject (value, key and index).
  • Key terms: coercion (converting a value to another type with as at runtime); format (a Java DecimalFormat or java.time pattern on a coercion); mode (date parsing strictness: SMART, STRICT, LENIENT); criteria (the lambda result that orderBy sorts on or filter tests); range selector ([-1 to 0], which reverses an array).

Key facts

Coercion properties
Detail
class, format, locale, mode, unit
Number to String
Detail
22 as String {format: ".00"} returns "22.00"
Trailing zeroes
Detail
Since DataWeave 2.5, writing numbers directly strips trailing zeroes
Date literal
Detail
ISO-8601, Date is |uuuu-MM-dd|
mode values
Detail
SMART, STRICT, LENIENT; only STRICT errors on invalid dates
Year letters
Detail
u = year (recommended), y = year of era, uu = two digits
Other letters
Detail
D = day of year, M = month, d = day of month, m = minute
Relational mixed types
Detail
Right operand coerced to the left operand's type
== vs ~=
Detail
"true" == true is false; "true" ~= true is true
orderBy direction
Detail
Ascending only; reverse with [-1 to 0]
filter lambda
Detail
(item, index); keeps items where it returns true
filterObject lambda
Detail
(value, key, index); returns an object
Sources for this section (7)
  • Why does "12" > 8 evaluate to false?
  • When should you add mode: "STRICT" to a date coercion?
  • Why does [3,2,3] orderBy $ return [2,3,3] rather than [3,3,2]?
  • When does a number coerced with as String {format: ".00"} keep its trailing zeroes?
  • Why is uuuu preferred over yyyy for years?

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 (9 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