Questions tagged [dataweave]

The DataWeave Language is a powerful template engine that allows you to transform data to and from any kind of format (XML, CSV, JSON, Pojos, Maps, etc).

DataWeave is the MuleSoft expression language for accessing and transforming data that travels through a Mule app. DataWeave is tightly integrated with the Mule runtime engine, which runs the scripts and expressions in your Mule app.

DataWeave scripts act on data in the Mule event. Most commonly, you use it to access and transform data in the message payload. For example, after a component in your app retrieves data from one system, you can use DataWeave to modify and output selected fields in that data to a new data format, then use another component in your app to pass on that data to another system.

Full Reference

https://docs.mulesoft.com/mule-user-guide/v/3.7/dataweave-reference-documentation

https://docs.mulesoft.com/mule-runtime/4.2/dataweave

1845 questions
2
votes
2 answers

Dataweave 2.0 withMaxSize function

I've transformation in external dwl file. I'm trying to use 'withMaxSize' to limit the size of string. But I'm getting below issue. fun providerObjMapping(payload) = (if(! isEmpty(payload.ProviderUniqueID) ) { …
Kiran
  • 29
  • 1
  • 8
2
votes
1 answer

Dataweave: Add a sum in an Object

I want to add a sum field in an object. Here is the trivial code I did: %dw 2.0 output application/json fun compute(a) = a var demo= { a: compute(1), b: compute(2), c: compute(4), sum:…
2
votes
1 answer

Mule 4 : Dataweave 2.0 : is there any alternative of Java 8 Streams anyMatch() method in Dataweave 2.0?

Scenario : Given an array consisting of objects representing a students marks and role in various subjects, I want to filter and see if there are any subjects where a particular student failed. var sampleArray = [ { "studentName" :…
Bibek Kr. Bazaz
  • 505
  • 10
  • 34
2
votes
4 answers

Dataweave: Create ranking from scores

With the following input: [5,5,4,4,4,2,2,1] I want to generate the following output: [ { "points": 5, "rank": 1 }, { "points": 5, "rank": 1 }, { "points": 4, "rank": 3 }, { "points": 4, "rank": 3 }, …
2
votes
3 answers

Using p() function in Transform Message in Mule Plugin

I have a mule plugin added as a dependency in my Project-A, In the mule-plugin I have defined a Transform Message where I am referring the values from the properties file defined in the plugin using p('property_name'). But it is throwing an error.…
Sufi
  • 186
  • 1
  • 2
  • 12
2
votes
6 answers

Mulesoft DataWeave 2.0 - conditionally change a single nested value

A status in XML needs to change before it gets forwarded. If RESPONSE.OUTBOUND.STATUS is equal to "ERR", it needs to say "FAILURE" instead. Other messages that STATUS may contain must remain as is. Sample XML before processing:
Tony
  • 2,658
  • 2
  • 31
  • 46
2
votes
2 answers

improve leftJoin nested mapObject when equivalence do and do not match

I am using the following dataweave function, and it does works. %dw 2.0 import * from dw::core::Arrays output application/json var mysqlInvoices = [ { "id": 1, "owner": "Joseph" }, { "id": 2, "owner":…
mhery
  • 2,097
  • 4
  • 26
  • 35
2
votes
2 answers

join data by position of different json elements on dataweave 2.0

I have this JSON output of a SAP function: { "Z_HYD_GET_INVOICES": { "import": { "BRANCH": "0142", "DOCNUMS": null, "FINAL_DATE": "Tue Oct 08 00:00:00 BST 2019", "INITIAL_DATE": "Mon Oct 07…
mhery
  • 2,097
  • 4
  • 26
  • 35
2
votes
2 answers

Convert Delimiter fille to JSON format using Dataweave in Mule

I need to convert existing delimiter file to json format using dataweave in mule. Sample Input: Name~#~ID~#~Company~#~Address SRI~#~1~#~Infy~#~Bangalore Rahul~#~2~#IBM~#~US John~#~3~#~SF~#~UK Sample outPut { Name: Sri ID: 1 Company: Infy Adress:…
Sri Rockz
  • 85
  • 1
  • 9
2
votes
2 answers

Zip key and value arrays into one object with Dataweave

I need to generate a single object starting from two arrays, one with the key names and the other with the values. I was able to get it using the following code: var keys = ["fieldA","fieldB","fieldC"] var values = [45,"data", {some:…
Jorge Garcia
  • 1,313
  • 8
  • 14
2
votes
3 answers

Attaching multiple csv files dynamically in a single email using Mule 4

I need to extract CSVData for each transaction and send the extracted csv files as multiple attachments in a single email using SMTP connector. Could you please let me know, how Can I extract CSV payload dynamically based on Transaction array and…
Deeps
  • 47
  • 9
2
votes
2 answers

How to use nested "map"

I would like to map a json, based on some nested attribute, but somehow there seems to be a stupid mistake I make. My input: [ { "productNo": "00011111", "items": [ { "color": "000000000006000060", }, { …
2
votes
1 answer

Dataweave Array Difference

I have 2 arrays. arr1 would be a superset and arr2 would be a subset and size of arr2 will always be less than arr1. I'd like to find out what values in arr1 that are not in arr2. e.g. arr1 = [ "07d65369-78eb-4afb-aba8-710ac146b93f", …
Varun Verma
  • 704
  • 2
  • 10
  • 20
2
votes
2 answers

DataWeave 2.0 If else condition

Am fairly new to Dataweave, trying to achieve simple if else condition based on below if (vars.country == "USA") { currency: "USD" } else { currency: "EUR" } This works fine. However, when I am trying with other json variables as below, it…
Ranjith Reddy
  • 129
  • 1
  • 3
  • 12
2
votes
1 answer

Is it posible to use Dataweave mask or update functions with conditions that depend on dynamic data?

I need to mask some fields which are dynamic. This is what I'm using now: var data = { a: 1, b: 2, c: 3, d: 4, e: 5 } var mask = { a: " ", d: "0"} --- data mapObject ((value, key, index) -> (key): mask[key] default value ) And I'm getting the…
Jorge Garcia
  • 1,313
  • 8
  • 14