# Coercing, formatting, ordering and filtering in DataWeave

*MuleSoft Developer Study Guide · Transforming Data · Last updated October 28, 2026 · https://www.certifyforce.com/study-guide/mulesoft-developer/transforming-data/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.

- Certification: Salesforce MuleSoft Developer
- Exam section: Transforming Data
- Study guide: https://www.certifyforce.com/study-guide/mulesoft-developer

**Official exam objective:**

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

## 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

| Fact | Detail | Source |
|---|---|---|
| Coercion properties | `class`, `format`, `locale`, `mode`, `unit` | [Type Coercion with DataWeave](https://docs.mulesoft.com/dataweave/latest/dataweave-types-coercion) |
| Number to String | `22 as String {format: ".00"}` returns `"22.00"` | [Type Coercion with DataWeave](https://docs.mulesoft.com/dataweave/latest/dataweave-types-coercion) |
| Trailing zeroes | Since DataWeave 2.5, writing numbers directly strips trailing zeroes | [Type Coercion with DataWeave](https://docs.mulesoft.com/dataweave/latest/dataweave-types-coercion) |
| Date literal | ISO-8601, `Date` is `\|uuuu-MM-dd\|` | [DataWeave Types](https://docs.mulesoft.com/dataweave/latest/dataweave-types) |
| `mode` values | SMART, STRICT, LENIENT; only STRICT errors on invalid dates | [Type Coercion with DataWeave](https://docs.mulesoft.com/dataweave/latest/dataweave-types-coercion) |
| Year letters | `u` = year (recommended), `y` = year of era, `uu` = two digits | [Format Dates and Times](https://docs.mulesoft.com/dataweave/latest/dataweave-cookbook-format-dates) |
| Other letters | `D` = day of year, `M` = month, `d` = day of month, `m` = minute | [Format Dates and Times](https://docs.mulesoft.com/dataweave/latest/dataweave-cookbook-format-dates) |
| Relational mixed types | Right operand coerced to the left operand's type | [DataWeave Operators](https://docs.mulesoft.com/dataweave/latest/dw-operators) |
| `==` vs `~=` | `"true" == true` is false; `"true" ~= true` is true | [DataWeave Operators](https://docs.mulesoft.com/dataweave/latest/dw-operators) |
| `orderBy` direction | Ascending only; reverse with `[-1 to 0]` | [orderBy](https://docs.mulesoft.com/dataweave/latest/dw-core-functions-orderby) |
| `filter` lambda | `(item, index)`; keeps items where it returns true | [filter](https://docs.mulesoft.com/dataweave/latest/dw-core-functions-filter) |
| `filterObject` lambda | `(value, key, index)`; returns an object | [filterObject](https://docs.mulesoft.com/dataweave/latest/dw-core-functions-filterobject) |

## Check yourself

- 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?

## Sources

- [Type Coercion with DataWeave](https://docs.mulesoft.com/dataweave/latest/dataweave-types-coercion)
- [Format Dates and Times](https://docs.mulesoft.com/dataweave/latest/dataweave-cookbook-format-dates)
- [orderBy](https://docs.mulesoft.com/dataweave/latest/dw-core-functions-orderby)
- [filter](https://docs.mulesoft.com/dataweave/latest/dw-core-functions-filter)
- [filterObject](https://docs.mulesoft.com/dataweave/latest/dw-core-functions-filterobject)
- [DataWeave Operators](https://docs.mulesoft.com/dataweave/latest/dw-operators)
- [DataWeave Types](https://docs.mulesoft.com/dataweave/latest/dataweave-types)
- [Parse Dates with DataWeave](https://docs.mulesoft.com/dataweave/latest/dataweave-cookbook-parse-dates)

## About the full unit

The "Core concepts", "Exam traps" and "Worked scenario" sections of this unit, its 9 linked practice questions, and unlimited timed mock exams are included with the MuleSoft Developer pack (USD $19): https://www.certifyforce.com/practice-exams
