Created
October 9, 2020 19:25
-
-
Save ravitejagrt/8068c9b86acf1da163ac963eca0e0d34 to your computer and use it in GitHub Desktop.
Dataweave code to convert contents of array to a string using Dataweave 2.0 in Mule 4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%dw 2.0 | |
import * from dw::core::Strings | |
output application/json | |
var payload = [{ | |
"id": 1, | |
"name": "Book", | |
"quantity": 100 | |
}, | |
{ | |
"id": 2, | |
"name": "Pen", | |
"quantity": 1000 | |
}, | |
{ | |
"id": 3, | |
"name": "Bag", | |
"quantity": 20 | |
}] | |
var final = payload reduce ((item, value="Data:") -> | |
(value ++ "Id-" ++ item.id ++ ",Name-" ++ item.name ++ ",Quantity-" ++ item.quantity ++ ";") | |
) | |
--- | |
{ | |
"substringAfter": substringAfter(final, "Data:"), | |
"substringBeforeLast": substringBeforeLast( substringAfter(final, "Data:"), ";") | |
} | |
// look up functions substringAfter, substringBefore, substringAfterLast, substringBeforeLast |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment