Production-ready DataWeave 2.x patterns for MuleSoft developers — copy, paste, transform.
- MuleSoft developers looking for battle-tested DataWeave snippets
- Integration architects who need proven transformation patterns for enterprise mappings
- Teams migrating from DW 1.0 to 2.0 — see our migration guide
- Anyone studying for MuleSoft certification — real-world examples, not toy data
- 50 DataWeave patterns across 10 categories — each with realistic input/output, working code, and alternative syntax
- DW 2.x Cheatsheet — comprehensive quick-reference (PDF)
- Anti-Patterns Guide — 12 common mistakes and how to fix them
- DW 1.0 → 2.0 Migration Guide — side-by-side syntax changes
- Playground Tips — test any pattern in MuleSoft's online playground
1. Pick a pattern from the table of contents below.
2. Copy the code into your Mule project or the DataWeave Playground.
3. Try it — here's a working example you can paste right now:
%dw 2.0
output application/json
---
// Group employees by department, then count per group
payload groupBy $.department
mapObject ((employees, dept) -> {
(dept): sizeOf(employees)
})
// Input: [{"name":"Alice","department":"Eng"},{"name":"Bob","department":"Sales"},{"name":"Carol","department":"Eng"}]
// Output: {"Eng": 2, "Sales": 1}No install. No dependencies. Just working DataWeave.
| # | Category | Patterns | Difficulty Range |
|---|---|---|---|
| 01 | Array Manipulation | 8 patterns | Beginner → Advanced |
| 02 | Object Transformation | 6 patterns | Beginner → Advanced |
| 03 | String Operations | 5 patterns | Beginner → Intermediate |
| 04 | Type Coercion | 4 patterns | Beginner → Advanced |
| 05 | XML Handling | 5 patterns | Intermediate → Advanced |
| 06 | CSV Operations | 3 patterns | Beginner → Intermediate |
| 07 | Error Handling | 4 patterns | Beginner → Intermediate |
| 08 | Date/Time | 4 patterns | Beginner → Intermediate |
| 09 | Advanced Patterns | 5 patterns | Advanced |
| 10 | Real-World Mappings | 6 patterns | Intermediate → Advanced |
| Pattern | File | Difficulty |
|---|---|---|
| Filter by Condition | filter-by-condition.dwl |
Beginner |
| Map Transform | map-transform.dwl |
Beginner |
| Flatten Nested Arrays | flatten-nested.dwl |
Intermediate |
| Group by Field | group-by-field.dwl |
Intermediate |
| Distinct Values | distinct-by.dwl |
Intermediate |
| Order/Sort | order-by.dwl |
Beginner |
| Reduce/Accumulate | reduce-accumulate.dwl |
Advanced |
| Zip Arrays | zip-arrays.dwl |
Intermediate |
| Pattern | File | Difficulty |
|---|---|---|
| Rename Keys | rename-keys.dwl |
Beginner |
| Remove Keys | remove-keys.dwl |
Beginner |
| Merge Objects | merge-objects.dwl |
Intermediate |
| Pluck Values | pluck-values.dwl |
Intermediate |
| Dynamic Keys | dynamic-keys.dwl |
Advanced |
| Nested Object Update | nested-object-update.dwl |
Advanced |
| Pattern | File | Difficulty |
|---|---|---|
| Split and Join | split-join.dwl |
Beginner |
| Regex Match/Replace | regex-match-replace.dwl |
Intermediate |
| Case Conversion | camel-to-snake.dwl |
Intermediate |
| Template Strings | template-strings.dwl |
Beginner |
| String Padding | string-padding.dwl |
Intermediate |
| Pattern | File | Difficulty |
|---|---|---|
| String to Date | string-to-date.dwl |
Intermediate |
| Number Formatting | number-formatting.dwl |
Beginner |
| Boolean Handling | boolean-handling.dwl |
Beginner |
| Custom Types | custom-types.dwl |
Advanced |
| Pattern | File | Difficulty |
|---|---|---|
| XML to JSON | xml-to-json.dwl |
Intermediate |
| JSON to XML | json-to-xml.dwl |
Intermediate |
| Namespace Handling | namespace-handling.dwl |
Advanced |
| CDATA Handling | cdata-handling.dwl |
Intermediate |
| Attribute Extraction | attributes-extraction.dwl |
Intermediate |
| Pattern | File | Difficulty |
|---|---|---|
| CSV to JSON | csv-to-json.dwl |
Beginner |
| JSON to CSV | json-to-csv.dwl |
Beginner |
| Custom Separator | custom-separator.dwl |
Intermediate |
| Pattern | File | Difficulty |
|---|---|---|
| Default Values | default-values.dwl |
Beginner |
| Try Pattern | try-pattern.dwl |
Intermediate |
| Error Response Builder | error-response-builder.dwl |
Intermediate |
| Conditional Error | conditional-error.dwl |
Intermediate |
| Pattern | File | Difficulty |
|---|---|---|
| Date Formatting | date-formatting.dwl |
Beginner |
| Timezone Conversion | timezone-conversion.dwl |
Intermediate |
| Date Arithmetic | date-arithmetic.dwl |
Intermediate |
| Epoch Conversion | epoch-conversion.dwl |
Intermediate |
| Pattern | File | Difficulty |
|---|---|---|
| Recursive Transform | recursive-transform.dwl |
Advanced |
| Custom Functions | custom-functions.dwl |
Advanced |
| Multi-Level GroupBy | multi-level-groupby.dwl |
Advanced |
| Dynamic Schema | dynamic-schema.dwl |
Advanced |
| Tail Recursion | tail-recursion.dwl |
Advanced |
| Pattern | File | Difficulty |
|---|---|---|
| Salesforce to SAP | salesforce-to-sap.dwl |
Advanced |
| REST API Flattening | rest-api-flattening.dwl |
Intermediate |
| EDI to JSON | edi-to-json.dwl |
Advanced |
| Batch Payload Split | batch-payload-split.dwl |
Intermediate |
| SOAP to REST | soap-to-rest.dwl |
Intermediate |
| Canonical Data Model | canonical-data-model.dwl |
Advanced |
- DW 2.x Cheatsheet | PDF download
- Anti-Patterns & Common Mistakes
- DW 1.0 → 2.0 Migration Guide
- Playground Tips
Reusable DataWeave utility libraries — import via Maven, no copy-paste needed.
| Module | Description | Status |
|---|---|---|
dw-string-utils |
15+ string functions (camelize, slugify, mask, etc.) | Live on Exchange |
dw-date-utils |
11 date functions (addDays, diffDays, toEpoch, etc.) | Live on Exchange |
dw-collection-utils |
15+ collection functions (chunk, deepMerge, pivot, etc.) | Live on Exchange |
dw-error-handler |
8 error functions (classifyError, isRetryable, etc.) | Live on Exchange |
dw-xml-helpers |
10 XML functions (stripNamespaces, xpathLike, etc.) | Live on Exchange |
We welcome contributions! See CONTRIBUTING.md for guidelines on adding patterns, submitting PRs, and code style requirements.
MIT — Copyright (c) 2026 Shakar Bisetty
Built by WeavePilot — curated DataWeave patterns for the MuleSoft community.