Skip to content
 
 

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DataWeave Patterns

License: MIT PRs Welcome DataWeave 2.x GitHub Stars 50+ Patterns

Production-ready DataWeave 2.x patterns for MuleSoft developers — copy, paste, transform.


Who Is This For?

  • 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

What's Inside


Quick Start

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.


Table of Contents

Patterns by Category

# 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

01 — Array Manipulation

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

02 — Object Transformation

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

03 — String Operations

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

04 — Type Coercion

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

05 — XML Handling

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

06 — CSV Operations

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

07 — Error Handling

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

08 — Date/Time

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

09 — Advanced Patterns

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

10 — Real-World Mappings

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

References


Anypoint Exchange Modules

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

Contributing

We welcome contributions! See CONTRIBUTING.md for guidelines on adding patterns, submitting PRs, and code style requirements.


License

MIT — Copyright (c) 2026 Shakar Bisetty


Built by WeavePilot — curated DataWeave patterns for the MuleSoft community.

About

Production-ready DataWeave 2.x patterns, cheatsheet, and anti-patterns for MuleSoft developers — by WeavePilot

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages