Skip to content

Instantly share code, notes, and snippets.

@ravitejagrt
Created October 9, 2020 19:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ravitejagrt/8068c9b86acf1da163ac963eca0e0d34 to your computer and use it in GitHub Desktop.
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
%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