Mastering DataWeave in MuleSoft: 100+ Practice Questions (Part 2)
Question 11 — Convert Names to Uppercase
Input
["john","sam","alex"]Expected Output
["JOHN","SAM","ALEX"]DataWeave Logic
%dw 2.0
output application/json
---
payload map upper($)Question 12 — Count Number of Elements
Input
[1,2,3,4,5]Expected Output
5DataWeave Logic
%dw 2.0
output application/json
---
sizeOf(payload)Question 13 — Get First Element from Array
Input
[10,20,30]Expected Output
10DataWeave Logic
%dw 2.0
output application/json
---
payload[0]Question 14 — Sort Numbers in Ascending Order
Input
[5,3,8,1]Expected Output
[1,3,5,8]DataWeave Logic
%dw 2.0
output application/json
---
payload orderBy $Question 15 — Reverse an Array
Input
[1,2,3,4]Expected Output
[4,3,2,1]DataWeave Logic
%dw 2.0
output application/json
---
payload[-1 to 0]Question 16 — Check if Array Contains a Value
Input
[1,2,3,4]Expected Output
true(Check if value 3 exists)
DataWeave Logic
%dw 2.0
output application/json
---
payload contains 3Question 17 — Rename Keys in Object
Input
{
"first_name":"John",
"last_name":"Doe"
}Expected Output
{
"firstName":"John",
"lastName":"Doe"
}DataWeave Logic
%dw 2.0
output application/json
---
{
firstName: payload.first_name,
lastName: payload.last_name
}Question 18 — Extract Unique Values
Input
[1,2,2,3,3,4]Expected Output
[1,2,3,4]DataWeave Logic
%dw 2.0
output application/json
---
payload distinctBy $Question 19 — Group Objects by Field
Input
[
{"name":"A","dept":"IT"},
{"name":"B","dept":"HR"},
{"name":"C","dept":"IT"}
]Expected Output
{
"IT":[
{"name":"A","dept":"IT"},
{"name":"C","dept":"IT"}
],
"HR":[
{"name":"B","dept":"HR"}
]
}DataWeave Logic
%dw 2.0
output application/json
---
payload groupBy $.deptQuestion 20 — Add New Field to Object
Input
{
"name":"Manoj",
"age":25
}Expected Output
{
"name":"Manoj",
"age":25,
"status":"active"
}DataWeave Logic
%dw 2.0
output application/json
---
payload ++ {status:"active"}🙌 Thanks for Reading
This is part of my ongoing DataWeave practice series.
Get Manoj Prabhakar Thakare’s stories in your inbox
Join Medium for free to get updates from this writer.
If this helped you, feel free to connect with me on LinkedIn — I’d love to learn about your MuleSoft journey and share knowledge together.
Stay tuned for the next parts!
🔥 Happy Integrating!



