DataWeave 2.0 Masterclass Β· Developer

DataWeave 2.0 Reference & Core Operators β€” Interview Questions & Scenarios (2026)

Core functions, map, filter, reduce, groupBy, pluck, flatten, null safe navigation, default values, and PII masking.

πŸ’» DataWeave 2.0 Reference & Core Operators

Core functions, map, filter, reduce, groupBy, pluck, flatten, null safe navigation, default values, and PII masking.

πŸ§ͺ
DataWeave 2.0 Studio Lab Engine v2.4
Live In-Browser Transformation Engine Β· 26 Real Enterprise Scenarios
πŸ“₯ INPUT PAYLOAD JSON
⚑ DATAWEAVE SCRIPT (%dw 2.0) output application/...
πŸ’‘ Try in Anypoint
πŸ“€ TRANSFORMED OUTPUT βœ… Evaluated
πŸ’‘ EXPLANATION & ARCHITECT INTERVIEW NOTES
What Happened? & Real Project Use Case
πŸ“ DataWeave 2.0 Reference & Core Operators
OPERATOREXAMPLERESULT / USE
mappayload map (item) -> {id: item.accountId}Transform each element. Returns same-size array.
filterpayload filter (item) -> item.status == "ACTIVE"Keep matching items. Returns smaller array.
groupBypayload groupBy ((item) -> item.region)Group into keyed object: {"EAST": [...], "WEST": [...]}
reducepayload reduce ((item, acc=0) -> acc + item.amount)Aggregate to single value β€” sum, build object.
orderBypayload orderBy ((item) -> item.name)Sort ascending. Negate for descending: -item.amount
distinctBypayload distinctBy ((item) -> item.accountId)Remove duplicates. Keeps first occurrence.
flatten[[1,2],[3,4]] flattenFlatten one level: [1,2,3,4]
mapObjectpayload mapObject ((v,k) -> {(upper(k)):v})Transform object key-value pairs. Returns object.
pluckpayload pluck ((v,k) -> {name:k, value:v})Convert object entries to array.
defaultnull default "N/A"Return fallback if null/missing.
?. (safe nav)payload.address?.city default ""Safe navigation β€” no NPE if parent is null.
$ and $$payload map $$ = current value, $$ = current index/key.
replace"1234567890" replace /\d(?=\d{4})/ with "*"Regex replace β€” mask all but last 4 digits.
uuid()uuid()Generate random UUID string.
now()(now() >> "America/New_York") as String {format:"yyyy-MM-dd"}Current timestamp in timezone.

DataWeave β€” Merge SAP XML + DynamoDB with null-safe defaults

DWL
%dw 2.0
output application/json
---
do {
var sap    = payload[0].payload
var dynamo = payload[1].payload
---
{
accountId:  sap.AccountID,
billingAmt: sap.TotalDue default 0,
language:   dynamo.language default "EN",
name: (sap.firstName default "") ++ " " ++ (sap.lastName default ""),
address: { street: sap.address.street default "N/A" }
}
}
// DataWeave β€” Find highest salary from array
%dw 2.0
output application/json
---
(payload orderBy ((item) -> -item.salary))[0].salary
// Third highest: [2].salary
// DataWeave β€” Count occurrences of a character
%dw 2.0
output application/json
---
sizeOf(("MULESOFT-CLOUD" splitBy "") filter (c) -> c == "O")
// Result: 2
Q1 [DEVELOPER] ⏱️ 1 min read Module R

What is the difference between sub-flow and private flow?

⚑ Self-Test Mode Ready
βœ“ ANSWER
ASPECTSUB-FLOWPRIVATE FLOW
Error handlerNo own error handler β€” inherits from caller flowHas its own error handler β€” independent error handling
TransactionRuns in caller's transaction contextRuns in its own transaction context
Invocationinvoked via flow-ref only (synchronous)flow-ref only β€” but with independent error scope
Use whenSimple code reuse within same flow's error scopeNeed independent error handling or transaction boundary
Q2 [DEVELOPER] ⏱️ 1 min read Module R

What is the difference between VM connector and flow reference?

⚑ Self-Test Mode Ready
βœ“ ANSWER

Flow Reference: Synchronous direct call to another flow in the SAME application. Same thread, same

transaction context. No messaging overhead.

VM Connector: Message-based communication using an in-memory/persistent queue within the

SAME application (VM queues are app-scoped). Can be synchronous (request-reply) or asynchronous

(one-way). Decouples sender from receiver β€” useful for async processing within one app.

Key difference: Flow-ref is a direct function call; VM is message-based within the app (like Anypoint

MQ but scoped to one application and not durable across cluster).

🎯🎯 Interview Pitch - Say It Like This (30 Sec)
"In Mule 4 architectures, I strictly reserve the VM Connector for intra-application asynchronous decoupling within a single deployment. In CloudHub 2.0, because replicas run as independent Kubernetes pods with ephemeral container disks, persistent VM queues do not replicate across pods. For reliable cross-replica or cross-application messaging, I always architect with Anypoint MQ instead."
πŸ’ΌπŸ’Ό Real-Time Project Example

Project: Retail & E-Commerce β€” High-Throughput Notification Dispatcher.

Problem: During peak traffic of 45,000 peak orders/hour, synchronous execution of audit logging was adding 700ms to the main transaction flow.

What I Did: Decoupled the logging flow using an in-memory VM queue with a dedicated listener thread pool, allowing the primary API to return HTTP 202 immediately.

Result: Reduced client response time from 1.2s to 180ms while handling logging asynchronously without message drops.

Q3 [DEVELOPER] ⏱️ 1 min read Module R

What is fan-in and fan-out? How do you implement them?

⚑ Self-Test Mode Ready
βœ“ ANSWER

Fan-Out: Send same message to multiple destinations. Implementation: Scatter-Gather (parallel

routes), Anypoint MQ Exchange (one publish β†’ all bound queues get copy), or multiple MQ publish

steps.

Fan-In: Collect results from multiple parallel paths into one. Scatter-Gather automatically fan-in: waits

for all routes, aggregates into an array. For MQ fan-in: use a separate aggregation flow that collects

messages keyed by correlationId with a TTL-based ObjectStore to accumulate all parts before

continuing.

Q4 [DEVELOPER] ⏱️ 1 min read Module R

What are streaming strategies in MuleSoft? Which is the default?

⚑ Self-Test Mode Ready
βœ“ ANSWER
STRATEGYBEHAVIORUSE WHEN
Non-Repeatable StreamingStream read once, not buffered β€” most memory-efficientLarge files you process only once, don't need to re-read
Repeatable In-MemoryBuffered in memory up to threshold, then diskNeed to re-read stream multiple times, moderate size
Repeatable File Store (default)Buffered to temporary file on disk β€” repeatableLarge payloads, need multiple reads without OOM risk

Default in Mule 4: Repeatable File Store Streaming for SFTP connector. For HTTP responses: non-repeatable by default unless responseStreamingMode is set. Use streaming for CSV files >50MB.

Q5 [DEVELOPER] ⏱️ 1 min read Module R

How do you set up HTTPS connection in MuleSoft? One-way vs two-way SSL?

⚑ Self-Test Mode Ready
βœ“ ANSWER

One-way SSL (server authentication only): Client verifies server's certificate. Server does NOT verify

client. Standard HTTPS. In MuleSoft: HTTP Listener needs tlsContext with keyStore (server cert).

HTTP Request needs tlsContext with trustStore (CA cert to trust server).

Two-way SSL (mutual TLS / mTLS): Both client and server present certificates and verify each other.

In MuleSoft HTTP Request: configure BOTH a trustStore (to verify server) AND a keyStore (client

certificate to present to server). Used for machine-to-machine authentication without

username/password.

Q6 [DEVELOPER] ⏱️ 1 min read Module R

What is VPC and VPN in CloudHub? What is SLB vs DLB?

⚑ Self-Test Mode Ready
βœ“ ANSWER

VPC (Virtual Private Cloud): Private isolated network segment in CloudHub where your Mule apps

run. Isolates your apps from other CloudHub customers. Required for DLB.

VPN: Encrypted tunnel connecting your CloudHub VPC to your on-premise data center. Mule apps in

VPC can access internal systems (SAP, databases) via private IP through VPN.

SLB (Shared Load Balancer): Multi-tenant, shared CloudHub infrastructure. Public IPs. Suitable for

lower-security workloads. Free.

DLB (Dedicated Load Balancer): Your own private load balancer in a VPC. Custom domain names,

custom SSL certificates, private IPs. Required for VPN-connected on-premise access. Additional cost

but necessary for enterprise production deployments.

πŸ”Ή DataWeave Coding Questions

🎯🎯 Interview Pitch - Say It Like This (30 Sec)
"In our modern deployments, we prioritize CloudHub 2.0 Private Spaces and Runtime Fabric on Kubernetes. We size applications using fractional vCores (like 0.2 to 1 vCore) with at least two replicas across availability zones to guarantee high availability, zero-downtime rolling updates, and internal ingress routing with automated Mutual TLS termination."
πŸ’ΌπŸ’Ό Real-Time Project Example

Project: Logistics β€” CloudHub 2.0 Multi-Region Migration.

Problem: Legacy single-worker CloudHub 1.0 applications suffered 4-minute downtimes during monthly patching and could not meet corporate DR recovery time objectives.

What I Did: Migrated 28 APIs to CloudHub 2.0 Private Spaces with dual replicas per app across multi-AZs, configuring automated ingress path routing and CI/CD canary deployments.

Result: Achieved 99.99% service availability with true zero-downtime deployments and reduced infrastructure spend by 22%.

Q7 [DEVELOPER] ⏱️ 1 min read Module R

How do you call a Java file in DataWeave? How do you invoke a flow in DataWeave?

⚑ Self-Test Mode Ready
βœ“ ANSWER

Call Java in DataWeave:

DataWeave β€” Call Java static method

DWL
%dw 2.0
import java!com:-enterprise:-utils:-StringUtils
output application/json
---
StringUtils:-formatAccountNumber(payload.accountId)
Invoke flow from DataWeave: Not directly possible in Mule 4 DataWeave. Flows are invoked via in
XML. If you need to call a flow from within a transform, use a to store DataWeave result, then
separately after the transform block.
🎯🎯 Interview Pitch - Say It Like This (30 Sec)
"DataWeave 2.0 is the core engine of our transformation layer. Rather than writing bulky Java components or iterative loops, I leverage DataWeave's functional paradigmsβ€”using map, filter, groupBy, and tail-recursive functionsβ€”and employ streaming annotations like @StreamCapable for multi-gigabyte payloads to maximize CPU cache locality and keep memory consumption minimal."
πŸ’ΌπŸ’Ό Real-Time Project Example

Project: Insurance β€” High-Volume Payload Transformation Service.

Problem: Transforming a 60MB nested XML payload containing 30,000 line items was consuming 1.2GB of heap memory and causing garbage collection pauses of up to 4 seconds.

What I Did: Rewrote the script using DataWeave 2.0 streaming with pluck, groupBy, and indexed lookups, avoiding eager array loading into JVM heap.

Result: Reduced memory footprint by 82% and dropped transformation execution time from 4.1s to 240ms.

Q8 [DEVELOPER] ⏱️ 1 min read Module R

Write DataWeave to mask a credit card number β€” show only last 4 digits.

⚑ Self-Test Mode Ready
βœ“ ANSWER

DataWeave β€” Credit card masking

DWL
%dw 2.0
output application/json
---
// Input: "1234567890123456"
// Output: "************3456"
payload.cardNumber replace /\d(?=\d{4})/ with "*"
// Alternative β€” mask first 12:
(payload.cardNumber[0 to 11] replace /\d/ with "*") ++ payload.cardNumber[12 to -1]
🎯🎯 Interview Pitch - Say It Like This (30 Sec)
"DataWeave 2.0 is the core engine of our transformation layer. Rather than writing bulky Java components or iterative loops, I leverage DataWeave's functional paradigmsβ€”using map, filter, groupBy, and tail-recursive functionsβ€”and employ streaming annotations like @StreamCapable for multi-gigabyte payloads to maximize CPU cache locality and keep memory consumption minimal."
πŸ’ΌπŸ’Ό Real-Time Project Example

Project: Aviation β€” High-Volume Payload Transformation Service.

Problem: Transforming a 60MB nested XML payload containing 30,000 line items was consuming 1.2GB of heap memory and causing garbage collection pauses of up to 4 seconds.

What I Did: Rewrote the script using DataWeave 2.0 streaming with pluck, groupBy, and indexed lookups, avoiding eager array loading into JVM heap.

Result: Reduced memory footprint by 82% and dropped transformation execution time from 4.1s to 240ms.

Q9 [DEVELOPER] ⏱️ 1 min read Module R

Write DataWeave to find even numbers from [1,2,3,4,5,6] and swap two values.

⚑ Self-Test Mode Ready
βœ“ ANSWER

DataWeave β€” Even numbers + swap

DWL
%dw 2.0
output application/json
---
// Even numbers:
[1,2,3,4,5,6] filter (n) -> (n mod 2) == 0
// Result: [2, 4, 6]
// Swap a=1, b=2:
do {
var a = 1
var b = 2
---
{ a: b, b: a }
}
// Result: { a: 2, b: 1 }
🎯🎯 Interview Pitch - Say It Like This (30 Sec)
"DataWeave 2.0 is the core engine of our transformation layer. Rather than writing bulky Java components or iterative loops, I leverage DataWeave's functional paradigmsβ€”using map, filter, groupBy, and tail-recursive functionsβ€”and employ streaming annotations like @StreamCapable for multi-gigabyte payloads to maximize CPU cache locality and keep memory consumption minimal."
πŸ’ΌπŸ’Ό Real-Time Project Example

Project: Energy & Utility β€” High-Volume Payload Transformation Service.

Problem: Transforming a 60MB nested XML payload containing 30,000 line items was consuming 1.2GB of heap memory and causing garbage collection pauses of up to 4 seconds.

What I Did: Rewrote the script using DataWeave 2.0 streaming with pluck, groupBy, and indexed lookups, avoiding eager array loading into JVM heap.

Result: Reduced memory footprint by 82% and dropped transformation execution time from 4.1s to 240ms.

Q10 [DEVELOPER] ⏱️ 1 min read Module R

Write a cron expression to trigger a flow daily at 10AM. Write RAML for books and songs

⚑ Self-Test Mode Ready

resources.

βœ“ ANSWER

Cron β€” Daily at 10AM EST

0 0 10 * * ?

// Second Minute Hour DayOfMonth Month DayOfWeek

// 0=second, 0=minute, 10=10AM, *=any day, *=any month, ?=any day of week

RAML β€” Books and Songs resources

RAML
#%RAML 1.0
title: Library API
version: v1
baseUri: /api
/books:
get:
description: Get all books
responses:
200:
body:
application/json:
post:
description: Create a book
/{bookId}:
get:
put:
🎯🎯 Interview Pitch - Say It Like This (30 Sec)
"We enforce an uncompromising API-first design methodology. Before a single line of Mule XML is scaffolded, we specify the API contract in RAML 1.0 or OAS 3.0 using Design Center, leveraging reusable Exchange fragments for canonical data types and security traits. Once reviewed with consumer teams, APIKit auto-generates routing logic with strict input validation, linked to API Manager via Autodiscovery."
πŸ’ΌπŸ’Ό Real-Time Project Example

Project: Retail & E-Commerce β€” API-led Microservices Modernization.

Problem: Frontend and backend teams worked in silos, leading to contract discrepancies, breaking changes, and 3-week delays during integration testing.

What I Did: Standardized RAML 1.0 API specifications with modular DataTypes and mock services in Exchange, enforcing API Autodiscovery and Client ID enforcement policies.

Result: Enabled consumer teams to develop against live mocks 4 weeks earlier, eliminating contract defects and accelerating time-to-market by 35%.

← Production Best Practices & Naming StandarEnterprise Utility & Energy Platform Deep β†’